Subversion Repositories camp_sysinfo_client_3

Rev

Rev 49 | Go to most recent revision | Details | Compare with Previous | 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
 
48 rodolico 16
 
2 rodolico 17
BEGIN {
18
   push @INC, shift;
19
}
20
 
21
use library;
22
 
23
# the commands this script will use
24
my %commands = ( 
25
                  'free' => '', 
26
                  'awk' => '', 
27
                  'grep' => '',
28
                  'tail' => '',
29
                  'uname' => ''
30
               );
31
 
32
# The files/directories the script will use
33
my %directory = (
34
                  '/proc/cpuinfo' => 0,
35
                  '/proc/uptime' => 0,
36
                  '/tmp/rodolico' => 0
37
                );
38
 
39
# check the commands for validity
40
foreach my $command ( keys %commands ) {
41
   $commands{$command} = &validCommandOnSystem( $command );
42
}
43
 
44
# check the file/directory exists
45
foreach my $dir ( keys %directory ) {
46
   $directory{$dir} =  1 if (-e $dir);
47
}
48
 
49
# category we will use for all values found
50
# see sysinfo for a list of valid categories
51
my $CATEGORY = 'system';
52
 
53
# make sure the commands will work before we run them.
54
if ( $commands{'awk'} && $commands{'grep'} ) { # we need grep and awk for all these
55
   print "$CATEGORY\tmemory\t" . &cleanUp('', qx(free | grep Mem | awk '{print \$2}')) . "\n" if $commands{'free'};
56
   if ( $directory{'/proc/cpuinfo'} ) { # and we need /proc/cpuinfo file for these
57
      print "$CATEGORY\tnum_cpu\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep processor | wc -l | awk '{print \$1}')) . "\n";
58
      print "$CATEGORY\tcpu_speed\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep MHz | tail -n1 | awk '{print \$4}')) . "\n";
59
      print "$CATEGORY\tcpu_type\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep vendor_id | tail -n 1 | awk '{print \$3}')) . "\n";
60
   }
61
}
62
# all this needs is uname
63
print "$CATEGORY\tcpu_sub\t" . &cleanUp('', qx(uname -m)) . "\n" if $commands{'uname'};
64
 
65
# need /proc/uptime to get the uptime
66
if ( $directory{'/proc/uptime'} ) {
67
   my $uptime = qx(cat /proc/uptime);
68
   $uptime =~ m/(\d+)/;
69
   $uptime = int($1); # uptime now has the up time in seconds
70
   print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
71
   print "$CATEGORY\tuptime\t" . $uptime . "\n";
72
}
73
 
74
exit 0;