Subversion Repositories camp_sysinfo_client_3

Rev

Rev 69 | Rev 244 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#!/usr/bin/env perl
use warnings;
use strict;  

# Description: Gets information on Unix based systems

our $VERSION = '1.1';

# Basic Unix module for sysinfo client
# Author: R. W. Rodolico
# Date:   2016-04-08

# gets additional systems information on Linux machine using some standard
# utilities


BEGIN {
   push @INC, shift;
}

use library;

# the commands this script will use
my %commands = ( 
                  'free' => '', 
                  'awk' => '', 
                  'grep' => '',
                  'tail' => '',
                  'uname' => ''
               );
               
# The files/directories the script will use
my %directory = (
#                  '/proc/cpuinfo' => 0,
                  '/proc/uptime' => 0,
#                  '/tmp/rodolico' => 0
                );

# check the commands for validity
foreach my $command ( keys %commands ) {
   $commands{$command} = &validCommandOnSystem( $command );
}

# check the file/directory exists
foreach my $dir ( keys %directory ) {
   $directory{$dir} =  1 if (-e $dir);
}

# category we will use for all values found
# see sysinfo for a list of valid categories
my $CATEGORY = 'system';


# this is now done via dmidecode module
# make sure the commands will work before we run them.
#if ( $commands{'awk'} && $commands{'grep'} ) { # we need grep and awk for all these
#   print "$CATEGORY\tmemory\t" . &cleanUp('', qx(free | grep Mem | awk '{print \$2}')) . "\n" if $commands{'free'};
#   if ( $directory{'/proc/cpuinfo'} ) { # and we need /proc/cpuinfo file for these
#      print "$CATEGORY\tnum_cpu\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep processor | wc -l | awk '{print \$1}')) . "\n";
#      print "$CATEGORY\tcpu_speed\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep MHz | tail -n1 | awk '{print \$4}')) . "\n";
#      print "$CATEGORY\tcpu_type\t" . &cleanUp('', qx(cat /proc/cpuinfo | grep vendor_id | tail -n 1 | awk '{print \$3}')) . "\n";
#   }
#}
# all this needs is uname
#print "$CATEGORY\tcpu_sub\t" . &cleanUp('', qx(uname -m)) . "\n" if $commands{'uname'};

# need /proc/uptime to get the uptime
if ( $directory{'/proc/uptime'} ) {
   my $uptime = qx(cat /proc/uptime);
   $uptime =~ m/(\d+)/;
   $uptime = int($1); # uptime now has the up time in seconds
   print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
   print "$CATEGORY\tuptime\t" . $uptime . "\n";
}

exit 0;