cliftonsmithhp has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl # Show last logins for every user in /etc/passwd # open(LASTLOGIN,"last|") || die "Cannot run 'last' command\n"; while (<LASTLOGIN>) { next if $_ eq ""; if (/^wtmp begin/) {$begin=$_ ; next}; ($name,$tty,$date)=/(\S+)\s+(\S+)\s+(\S+\s+\S+\s+\S+)/; $user{$name}=$date unless $user{$name}; } print $begin; close(LASTLOGIN); open(PASSWD,"/etc/passwd") || die "Cannot open '/etc/passwd'\n"; while (<PASSWD>) { next if /^\+/; ($name,$rest)=split(":"); $user{$name}="**No Logon Since /etc/wtmp File Created**" unless $user{ +$name}; } foreach $name (sort keys(%user)) { printf "%-10s %s\n",$name,$user{$name}; }
2004-10-19 Edited by Arunbear: Changed title from 'Easy one for the Monks !'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reporting last login according to wtmp for selected users
by jdporter (Paladin) on Oct 18, 2004 at 19:18 UTC | |
|
Re: Reporting last login according to wtmp for selected users
by gellyfish (Monsignor) on Oct 19, 2004 at 09:15 UTC | |
|
wanted: meaningful node titles
by rjbs (Pilgrim) on Oct 19, 2004 at 14:29 UTC |