Subversion Repositories camp_sysinfo_client_3

Rev

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
 
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 = (
153 rodolico 34
#                  '/proc/cpuinfo' => 0,
2 rodolico 35
                  '/proc/uptime' => 0,
153 rodolico 36
#                  '/tmp/rodolico' => 0
2 rodolico 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
 
153 rodolico 53
 
54
# this is now done via dmidecode module
2 rodolico 55
# make sure the commands will work before we run them.
153 rodolico 56
#if ( $commands{'awk'} && $commands{'grep'} ) { # we need grep and awk for all these
57
#   print "$CATEGORY\tmemory\t" . &cleanUp('', qx(free | grep Mem | awk '{print \$2}')) . "\n" if $commands{'free'};
58
#   if ( $directory{'/proc/cpuinfo'} ) { # and we need /proc/cpuinfo file for these
59
#      print "$CATEGORY\tnum_cpu\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep processor | wc -l | awk '{print \$1}')) . "\n";
60
#      print "$CATEGORY\tcpu_speed\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep MHz | tail -n1 | awk '{print \$4}')) . "\n";
61
#      print "$CATEGORY\tcpu_type\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep vendor_id | tail -n 1 | awk '{print \$3}')) . "\n";
62
#   }
63
#}
2 rodolico 64
# all this needs is uname
153 rodolico 65
#print "$CATEGORY\tcpu_sub\t" . &cleanUp('', qx(uname -m)) . "\n" if $commands{'uname'};
2 rodolico 66
 
67
# need /proc/uptime to get the uptime
68
if ( $directory{'/proc/uptime'} ) {
69
   my $uptime = qx(cat /proc/uptime);
70
   $uptime =~ m/(\d+)/;
71
   $uptime = int($1); # uptime now has the up time in seconds
72
   print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
73
   print "$CATEGORY\tuptime\t" . $uptime . "\n";
74
}
75
 
76
exit 0;