Last active
December 27, 2015 16:59
-
-
Save jonuwz/7358612 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use POSIX qw(strftime); | |
my %names; | |
my $fmt="%-24s%-9s%s\n"; | |
setpwent; | |
while (my ($name, $junk, $uid) = getpwent) { | |
$names{$uid} = $name; | |
} | |
endpwent; | |
open(my $last, '<', '/var/adm/lastlog'); | |
printf($fmt, "Username", "Port", "Latest"); | |
for (my $uid = 0; read($last, my $record, 28); $uid++) { | |
my ($time, $line, $host) = unpack('l A8 A16', $record); | |
if ($time) { | |
my $ptime = strftime("%a %b %e %T +0000 %Y", gmtime($time)); | |
printf( $fmt, $names{$uid}, $line, $ptime) if $names{$uid}; | |
} else { | |
printf( $fmt, $names{$uid}, "", "**Never logged in**") if $names{$uid}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
perl implementation of lastlog for Solaris