| Category: | Utility Scripts |
| Author/Contact Info | merlyn |
| Description: | View the last login times of everyone on your system. You may need to adjust the struct for unpacking or the location of your lastlog file. |
open LASTLOG, "/var/log/lastlog" or die; # location may vary
my $struct_lastlog = "L a8 a256"; # see "man lastlog" for struct sizes
my $size = length pack $struct_lastlog, 0, "", "";
while (my($user, $pwd, $uid) = getpwent) {
next unless seek LASTLOG, $size * $uid, 0;
next unless read(LASTLOG, my $buf, $size) == $size;
my ($time, $line, $host) = unpack $struct_lastlog, $buf;
s/\0*$// for $line, $host; # trim NULs
next unless $time;
printf "%8s %5d %30s %8s %s\n", $user, $uid, scalar localtime $time,
+ $line, $host;
}
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
&cow;Re: View last login times of everyone on your system
by Roy Johnson (Monsignor) on Jan 15, 2004 at 19:49 UTC | |
by merlyn (Sage) on Jan 15, 2004 at 19:57 UTC | |
by Roy Johnson (Monsignor) on Jan 15, 2004 at 20:23 UTC | |
|
Re: View last login times of everyone on your system
by gellyfish (Monsignor) on Jan 19, 2004 at 16:06 UTC | |
|
Re: View last login times of everyone on your system
by zentara (Cardinal) on Jan 19, 2004 at 15:32 UTC | |
by merlyn (Sage) on Jan 19, 2004 at 15:34 UTC | |
by zentara (Cardinal) on Jan 19, 2004 at 15:43 UTC |