--- projects/cms/source/host/generic/statgrab.pl 2001/02/05 17:13:26 1.26 +++ projects/cms/source/host/generic/statgrab.pl 2001/02/05 17:21:04 1.27 @@ -2,8 +2,8 @@ #----------------------------------------------------------------- # Machine statistics grabber -# $Author: pjm2 $ -# $Id: statgrab.pl,v 1.26 2001/02/05 17:13:26 pjm2 Exp $ +# $Author: tdb $ +# $Id: statgrab.pl,v 1.27 2001/02/05 17:21:04 tdb Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -50,7 +50,7 @@ exit(0); # the host should check this when reading data # means the host must be checked and updated to work with newer versions. sub print_ident() { - print 'version statgrab.pl $Revision: 1.26 $'; + print 'version statgrab.pl $Revision: 1.27 $'; print "\n"; } @@ -188,25 +188,69 @@ sub include_osver() { # sub to get system uptime. sub include_uptime() { + # debug stuff, all the different cases + + # normal + #my($uptime) = " 4:48pm up 49 day(s), 6:30, 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 days + #my($uptime) = " 4:48pm up 6:30, 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 hours + #my($uptime) = " 4:48pm up 49 day(s), 30 min(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 mins + #my($uptime) = " 4:48pm up 49 day(s), 6 hr(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 days and 0 mins + #my($uptime) = " 4:48pm up 6 hr(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 days and 0 hours + #my($uptime) = " 4:48pm up 30 min(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # 0 hours and 0 mins + #my($uptime) = " 4:48pm up 49 day(s), 201 users, load average: 0.33, 0.35, 0.38\n"; + # grab the uptime my($uptime) = `$uptimebin`; # work out the days, hours, and minutes if ($uptime =~ /hr/) { - # 0 minutes - $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:$2:0/; + # two possible cases here + if($uptime =~ /day/) { + # 0 minutes + $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; + $uptime = "$1:$2:0"; + } + else { + # 0 days and 0 minutes + $uptime =~ /up\s+([0-9]+)\s+/; + $uptime = "0:$1:0"; + } } elsif ($uptime =~ /min/) { - # 0 hours - $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:0:$2/; + # two possible cases here + if($uptime =~ /day/) { + # 0 hours + $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; + $uptime = "$1:0:$2"; + } + else { + # 0 days and 0 hours + $uptime =~ /up\s+([0-9]+)\s+/; + $uptime = "0:0:$1"; + } } elsif ($uptime =~ /day/) { - # normal - $uptime =~ s/up ([0-9]+) .*, ([0-9]+):([0-9]+)/$1:$2:$3/; + if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) { + # normal + $uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/; + $uptime = "$1:$2:$3"; + } + else { + # 0 hours and 0 mins + $uptime =~ /up\s+([0-9]+)/; + $uptime = "$1:0:0"; + } } else { # 0 days - $uptime =~ s/up ([0-9]+):([0-9]+)/0:$1:$2/; + $uptime =~ /up\s+([0-9]+):([0-9]+)/; + $uptime = "0:$1:$2"; } # turn into minutes