Subversion Repositories camp_sysinfo_client_3

Rev

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