#!/usr/local/bin/perl # Show last logins for every user in /etc/passwd # open(LASTLOGIN,"last|") || die "Cannot run 'last' command\n"; while () { 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 () { 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}; }