Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 rodolico 1
#! /usr/bin/perl -w
2
 
3
# gets additional systems information on Linux machine using some standard
4
# utilities
5
 
6
BEGIN {
7
   push @INC, shift;
8
}
9
 
10
use library;
11
 
12
# the commands this script will use
13
my %commands = ( 
14
                  'free' => '', 
15
                  'awk' => '', 
16
                  'grep' => '',
17
                  'tail' => '',
18
                  'uname' => ''
19
               );
20
 
21
# The files/directories the script will use
22
my %directory = (
23
                  '/proc/cpuinfo' => 0,
24
                  '/proc/uptime' => 0,
25
                  '/tmp/rodolico' => 0
26
                );
27
 
28
# check the commands for validity
29
foreach my $command ( keys %commands ) {
30
   $commands{$command} = &validCommandOnSystem( $command );
31
}
32
 
33
# check the file/directory exists
34
foreach my $dir ( keys %directory ) {
35
   $directory{$dir} =  1 if (-e $dir);
36
}
37
 
38
# category we will use for all values found
39
# see sysinfo for a list of valid categories
40
my $CATEGORY = 'system';
41
 
42
# make sure the commands will work before we run them.
43
if ( $commands{'awk'} && $commands{'grep'} ) { # we need grep and awk for all these
44
   print "$CATEGORY\tmemory\t" . &cleanUp('', qx(free | grep Mem | awk '{print \$2}')) . "\n" if $commands{'free'};
45
   if ( $directory{'/proc/cpuinfo'} ) { # and we need /proc/cpuinfo file for these
46
      print "$CATEGORY\tnum_cpu\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep processor | wc -l | awk '{print \$1}')) . "\n";
47
      print "$CATEGORY\tcpu_speed\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep MHz | tail -n1 | awk '{print \$4}')) . "\n";
48
      print "$CATEGORY\tcpu_type\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep vendor_id | tail -n 1 | awk '{print \$3}')) . "\n";
49
   }
50
}
51
# all this needs is uname
52
print "$CATEGORY\tcpu_sub\t" . &cleanUp('', qx(uname -m)) . "\n" if $commands{'uname'};
53
 
54
# need /proc/uptime to get the uptime
55
if ( $directory{'/proc/uptime'} ) {
56
   my $uptime = qx(cat /proc/uptime);
57
   $uptime =~ m/(\d+)/;
58
   $uptime = int($1); # uptime now has the up time in seconds
59
   print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
60
   print "$CATEGORY\tuptime\t" . $uptime . "\n";
61
}
62
 
63
exit 0;