--- projects/cms/source/host/generic/statgrab.pl 2001/01/22 23:21:34 1.13 +++ projects/cms/source/host/generic/statgrab.pl 2001/01/29 17:09:04 1.18 @@ -2,8 +2,8 @@ #----------------------------------------------------------------- # Machine statistics grabber -# $Author: tdb $ -# $Id: statgrab.pl,v 1.13 2001/01/22 23:21:34 tdb Exp $ +# $Author: pjm2 $ +# $Id: statgrab.pl,v 1.18 2001/01/29 17:09:04 pjm2 Exp $ # # A Perl script to return various information about a host machine # by examining the output of some common Unix/Linux commands. @@ -21,15 +21,17 @@ $| = 1; # You'd be silly not to use this ;) use strict; -# Path's +# Paths my($topbin) = "/usr/local/sbin/top"; my($dfbin) = "/usr/bin/df"; my($usersbin) = "/usr/ucb/users"; my($unamebin) = "/usr/bin/uname"; +my($uptimebin) = "/usr/bin/uptime"; # Run the following components: - &print_ident(); &include_osver(); +&include_uptime(); &include_users(); &include_top(); &include_disk(); @@ -48,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.13 $'; + print 'version statgrab.pl $Revision: 1.18 $'; print "\n"; } @@ -107,11 +109,12 @@ sub include_users() { # Find out all users on this machine. my($users) = `$usersbin`; - my(@users) = split(/\s+/, $users); + $users = "\n" unless defined $users; + chop $users; + my($users_count) = 0; + $users_count++ while $users =~ /\w+/g; + my($users_list) = $users." "; - my($users_count) = $#users + 1; - my($users_list) = $users; - &print_pair(1, "packet.users.count", $users_count); &print_pair(0, "packet.users.list", $users_list); } @@ -184,5 +187,15 @@ sub include_osver() { &print_pair(0, "packet.os.platform", $os_platform); &print_pair(0, "packet.os.sysname", $os_sysname); &print_pair(0, "packet.os.version", $os_version); + +} + +# sub to get system uptime. +sub include_uptime() { + + # Need a regexp guru to strip the junk on this line + my($uptime) = `$uptimebin`; + + &print_pair(0, "packet.os.uptime", $uptime); }