Subversion Repositories camp_sysinfo_client_3

Rev

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

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