diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/guprecords | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/guprecords b/src/guprecords index 888e9fc..3722470 100755 --- a/src/guprecords +++ b/src/guprecords @@ -1,4 +1,5 @@ #!/usr/bin/env perl + # guprecords (c) 2014, Paul Buetow # E-Mail: guprecords@mx.buetow.org WWW: http://codeberg.org/snonux/guprecords @@ -8,9 +9,11 @@ use v5.14; use Getopt::Long; use POSIX qw(strftime); +use Term::ANSIColor; our $VERSION = 'VERSION_DEVEL'; our $FLAG = 0; +our $NOW = time(); our %ARGS = ( all => 0, @@ -18,6 +21,8 @@ our %ARGS = ( nofqdn => 0, reverse => 0, total => 0, + nocolor => 0, + 'oldage=i' => 180, 'count=i' => 23, 'indir=s' => '.', ); @@ -70,12 +75,16 @@ sub out(\@;$) { my $name = $ARGS{nofqdn} ? $_->{hostname} : $_->{fqdn}; + print color 'bold' if !$ARGS{nocolor} and $_->{is_old}; + printf "%3d | %17s | %20s | %13s | %24s\n", $count, trimlen($name,17), trimlen($_->{kernel},20), uptime($_->{uptime}), (defined $show_bt ? ''.localtime($_->{bootime}) : ''); + + print color 'reset' if !$ARGS{nocolor} and $_->{is_old}; } do { unless ($ARGS{reverse}) { @@ -86,6 +95,14 @@ sub out(\@;$) { }; } +sub is_old($) { + my $time = shift; + # Count per day + my $oldage = 86400 * $ARGS{'oldage=i'}; + + return $NOW - $time < $oldage ? 1 : 0; +} + sub all() { my @records; @@ -106,6 +123,7 @@ sub all() { hostname => $hostname, kernel => $kernel, uptime => $uptime, + is_old => is_old $uptime + $boot, }; } @@ -125,7 +143,7 @@ sub total() { my $uptime_ = 0; my $kernel_; - my $highest = 0; + my ($highest, $newest) = (0, 0); open my $fh, $file or die "$file: $!\n"; while (<$fh>) { @@ -137,7 +155,9 @@ sub total() { if ($highest < $uptime) { $highest = $uptime; $kernel_ = $kernel; - } + } + + $newest = $uptime + $boot if $newest < $uptime + $boot; } close $file; @@ -145,6 +165,7 @@ sub total() { uptime => $uptime_, kernel => $kernel_, fqdn => $fqdn, + is_old => is_old $newest, }; } |
