I'm trying to parse some output generated by someone else's script, which uses the module, User::Utmpx. What I'm trying to do is breakup each line into three saved buffers, as demonstrated below:

Here's the actual data:

/var/adm/wtmpx begins on Fri Jun 7 16:40:21 2002 (488 days) ago flexlm FlexLM license manag Never logged in m12345 Shmoe,Ronald K. Last login Thu May 1 14:11:54 2003 (160 day +s ago) m54321 O'Schmoe,Karen D. Last login Sun Sep 29 15:39:43 2002 (37 +4 days ago) mresw3 Joe-Schmoe,Mira Never logged in mdsjlk Schmoe, Robert L. Last login Thu Sep 12 15:41:11 2002 (391 + days ago) oracle OraSchmoe Oracle user Never logged in sshd OpenSchmoe Privilege Se Never logged in web suitespot,httpd serv Never logged in
The save buffers should get populated like this (for example):
$1 = m54321 $2 = O'Schmoe,Karen D. $3 = Last login Sun Sep 29 15:39:43 2002 (374 days ago)
The problem I'm running into is dealing with the variable whitespace.

For thos interested, her's what I've tried, none of which works, obviously

$line =~ /(\w+)\s+(.*?)\s{2,9}(.*?)/ ; $line =~ s/(\w+)\s+(.*?)\s{2,9}(.*?)/$1 $2 $3/;
....and a few other broken permutations of the above.

If anyone is interested, the context of what I'm doing is, we've got a program which will return a list comparable to the data above. This returns a list of users who have not logged into a given server for N days.

My plan is to run this program on each server in our infrastructure and mail the output to an email alias. This alias is going to be the script that I'm asking for help on. My intent is for this script to parse the incoming data and create a report of which machines each user has "old" user account on, and finally concatenate it to a log file.

The resultant data structure would contain:

<username>
<server 1> <last login>
<server 2> <last login>
<server 3> <last login>

....and so on.

Edit by thelenm: fixed a broken code tag


In reply to more than one whitespace char as word anchor by blink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.