Subversion Repositories camp_sysinfo_client_3

Rev

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

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

# modified 20190419 RWR
# changed cleanup to remove encapsulating quotes

# Description: Library used by modules. Do NOT enable


our $VERSION = '1.3';

# set of libraries to be used by these modules


# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
#           chomps the string (removes trailing newlines)
#           removes all text BEFORE the delimiter, the delimiter, and any whitespace
#           thus, the string 'xxI Am x  a weird string' with a newline will become
#           'a weird string' with no newline
# will also look for single and double quotes surrounding entire string and remove them
# if they exist

sub cleanUp {
   my ($delimiter, $text) = @_;
   chomp $text;
   if ( $delimiter && $text =~ m/[^$delimiter]*$delimiter\s*(.*)/ ) {
      $text = $1;
   }
   if ( $text =~ m/^'(.*)'$/ ) {
      $text = $1;
   }
   if ( $text =~ m/^"(.*)"$/ ) {
      $text = $1;
   }
   return $text;
}

# checks if a command is valid on this system. If so, returns the full path to it
# else, returns empty string.
sub validCommandOnSystem {
   my $command = shift;
   $command = `which $command 2> /dev/null`;
   chomp $command;
   return -x $command ? $command : '';
}

sub getOperatingSystem {
   return &cleanUp('', qx(uname -s));
}   

sub getSysctlParameter {
   my ( $sysctl, $parameter ) = @_;
   my $result = qx( $sysctl $parameter );
   chomp $result;
   $result =~ s/$parameter:\s*//;
   return $result;
}

1;