--- projects/cms/source/host/generic/statgrab.pl 2001/01/28 19:53:39 1.15 +++ projects/cms/source/host/generic/statgrab.pl 2001/02/01 03:14:35 1.19 @@ -2,8 +2,8 @@ #----------------------------------------------------------------- # Machine statistics grabber -# $Author: pjm2 $ -# $Id: statgrab.pl,v 1.15 2001/01/28 19:53:39 pjm2 Exp $ +# $Author: tdb $ +# $Id: statgrab.pl,v 1.19 2001/02/01 03:14:35 tdb 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.15 $'; + print 'version statgrab.pl $Revision: 1.19 $'; print "\n"; } @@ -107,11 +109,11 @@ sub include_users() { # Find out all users on this machine. my($users) = `$usersbin`; - chop($users); - $users = "" unless defined $users; + $users = "\n" unless defined $users; + chop $users; my($users_count) = 0; $users_count++ while $users =~ /\w+/g; - my($users_list) = $users; + my($users_list) = $users." "; &print_pair(1, "packet.users.count", $users_count); &print_pair(0, "packet.users.list", $users_list); @@ -185,5 +187,16 @@ 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() { + + my($uptime) = `$uptimebin`; + $uptime =~ /up ([0-9]+) .*, ([0-9]+:[0-9]+)/; + $uptime = "$1:$2"; + + &print_pair(0, "packet.os.uptime", $uptime); }