From 36d9c53876362c3d98326150783d77dd4c13f00e Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Fri, 20 Jun 2014 00:19:11 +0200 Subject: add nofqdn switch --- docs/guprecords.pod | 20 ++++++++++++-------- src/guprecords | 15 ++++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/guprecords.pod b/docs/guprecords.pod index 4e28abc..d060e11 100644 --- a/docs/guprecords.pod +++ b/docs/guprecords.pod @@ -12,14 +12,6 @@ guprecords [--help] [--total|--all] [--count=i] [--indir=s] =over -=item --help - -Shows the help - -=item --total - -Aggregates a total uptime for every single host. - =item --all Shows every individual uptime of all hosts. @@ -28,10 +20,22 @@ Shows every individual uptime of all hosts. Show i num of entries. Default is 23. +=item --nofqdn + +Don't display the FQDNs + +=item --help + +Shows the help + =item --indir=s Read all the *.records files from dir s. Default is ./ +=item --total + +Aggregates a total uptime for every single host. + =back diff --git a/src/guprecords b/src/guprecords index ed353c7..b7d298f 100755 --- a/src/guprecords +++ b/src/guprecords @@ -14,9 +14,10 @@ our $FLAG = 0; our %ARGS = ( all => 0, - total => 0, - reverse => 0, help => 0, + nofqdn => 0, + reverse => 0, + total => 0, 'count=i' => 23, 'indir=s' => '.', ); @@ -67,9 +68,11 @@ sub out(\@;$) { map { return if $count++ == $ARGS{'count=i'}; + my $name = $ARGS{nofqdn} ? $_->{hostname} : $_->{fqdn}; + printf "%3d | %17s | %20s | %13s | %24s\n", $count, - trimlen($_->{fqdn},17), + trimlen($name,17), trimlen($_->{kernel},20), uptime($_->{uptime}), (defined $show_bt ? ''.localtime($_->{bootime}) : ''); @@ -88,6 +91,7 @@ sub all() { for my $file (<$ARGS{'indir=s'}/*.records>) { my ($fqdn) = $file =~ m#.*/(.*)\.records#; + my ($hostname) = $fqdn =~m#([^\.]+)#; my $uptime_total = 0; @@ -97,10 +101,11 @@ sub all() { my ($uptime,$boot,$kernel) = split ':'; push @records, { - uptime => $uptime, bootime => $boot, - kernel => $kernel, fqdn => $fqdn, + hostname => $hostname, + kernel => $kernel, + uptime => $uptime, }; } -- cgit v1.2.3