Skip to content

Instantly share code, notes, and snippets.

@jonuwz
Last active December 27, 2015 16:59
Show Gist options
  • Save jonuwz/7358612 to your computer and use it in GitHub Desktop.
Save jonuwz/7358612 to your computer and use it in GitHub Desktop.
#!/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};
}
}
@jonuwz
Copy link
Author

jonuwz commented Nov 7, 2013

perl implementation of lastlog for Solaris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment