Skip to content

Instantly share code, notes, and snippets.

@bvierra
Created August 6, 2013 13:57
#!/usr/bin/env perl
use strict;
use warnings;
my @files = ('/var/log/wtmp', '/var/log/wtmp.1');
my %TIMES;
foreach my $file (@files) {
parse($file);
}
foreach (sort keys %TIMES) {
next if $_ eq "reboot";
print "$_ $TIMES{$_}\n";
}
sub parse {
my $f = shift;
return if ! -r $f;
open my $fh, "last -f $f |";
while (<$fh>) {
if (my ($name,$days,$hours,$mins) = /^(\w+).+\((?:(\d+)\+)?(\d+):(\d+)/) {
$days = 0 if !$days;
$TIMES{$name} += 1440 * $days + 60 * $hours + $mins;
}
}
close($fh);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment