Subversion Repositories camp_sysinfo_client_3

Rev

Rev 55 | Rev 116 | 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: Library used by modules. Do NOT enable
20 rodolico 6
 
37 rodolico 7
our $VERSION = '1.2';
8
 
2 rodolico 9
# set of libraries to be used by these modules
10
 
11
 
20 rodolico 12
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
13
#           chomps the string (removes trailing newlines)
14
#           removes all text BEFORE the delimiter, the delimiter, and any whitespace
15
#           thus, the string 'xxI Am x  a weird string' with a newline will become
16
#           'a weird string' with no newline
17
 
2 rodolico 18
sub cleanUp {
19
   my ($delimiter, $text) = @_;
20
   chomp $text;
21
   return $text unless $delimiter;
22
   $text =~ m/[^$delimiter]*$delimiter\s*(.*)/;
23
   return $1;
24
}
25
 
26
# checks if a command is valid on this system. If so, returns the full path to it
27
# else, returns empty string.
28
sub validCommandOnSystem {
29
   my $command = shift;
30
   $command = `which $command 2> /dev/null`;
31
   chomp $command;
32
   return -x $command ? $command : '';
33
}
34
 
48 rodolico 35
sub getOperatingSystem {
36
   return &cleanUp('', qx(uname -s));
37
}   
38
 
55 rodolico 39
sub getSysctlParameter {
40
   my ( $sysctl, $parameter ) = @_;
41
   my $result = qx( $sysctl $parameter );
42
   chomp $result;
43
   $result =~ s/$parameter:\s*//;
44
   return $result;
45
}
46
 
20 rodolico 47
1;