Simple perl, designed to extract from wtmp, users who haven't login in over 365 days, it is the template that causing the headache
#!/usr/local/bin/perl
print $template = "A8 A4 A12 l s s s s l a16 l";
$recordsize = length(pack($template,( )));
open(WTMP,"/var/adm/wtmp") or die "Unable to open wtmp:$!\n";
while (read(WTMP,$record,$recordsize)) {
($user,$ttyid,$tty,$pid,$type,$term,$exit,$host,$time,$hostip)
+=unpack
($template,$record);
next unless $type == 7;
next unless $ttyid;
next if $ttyid eq "ftp";
next if $ttyid=~/\d+:\d+/;
$user=~y/\000//d; $ttyid=~y/\000//d; $tty=~y/\000//d; $host=~y
+/\000//d;
$hold{$user}=$time if $time >$hold{$user};
}
$over365=time()-365*24*60*60;
foreach $user (keys %hold) {
if ($hold{$user} < $over365) { printf( "%12s %d\n", $user, $ho
+ld{$user}
); }
};
_________________________________________
OUTPUT LOOKS LIKE THIS:
A8 A4 A12 l s s s s l a16 l kileykl 1043180949
romanst 1042640335
hallchar 1033636020
orsjrg 1035913589
dindiala 1035210784
smithpau 1045754579
orsbll 1042571980
orsmjr 1043676426
orsawb 1036078160
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.