Skip to content

Instantly share code, notes, and snippets.

@soh-i
Last active October 6, 2015 16:38
Show Gist options
  • Save soh-i/3022641 to your computer and use it in GitHub Desktop.
Save soh-i/3022641 to your computer and use it in GitHub Desktop.
ちょっと監視してた
#!/usr/bin/env perl
use strict;
use warnings;
my $name = {};
my @cmd = `last`;
for (reverse @cmd) {
next if $_ =~ /wtmp|^\s+/;
my ($user, undef, $from, $w, $m, $d, $t) = split /\s+/;
my $login_date = "$w $m$d $t";
$name->{$user}->{User} = $from;
$name->{$user}->{Count}++;
$name->{$user}->{Login} = $login_date;
}
foreach my $usr (sort
{ $name->{$b}->{Count} <=> $name->{$a}->{Count}
} keys %{ $name }) {
printf "%-10s", $usr;
printf "%-10s", $name->{$usr}->{Count};
printf "%-10s\n", $name->{$usr}->{Login};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment