in reply to Last logon and time for a system console
last comes in reverse time order already, so the first value assigned to any host will be the latest log in from that host.
#!/usr/bin/perl use strict; use warnings; my @last= `last`; my (%time, @details, $host); map{ @details=split(/ +/); $host=$details[2]; $time{$host}=join (' ', @details[3,4,5,6]) unless $time{$host} ; }@last[0..$#last - 2]; map{ print "$_, last login at $time{$_}\n"; } keys %time;
|
|---|