| 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 |
|
| 152 |
rodolico |
11 |
our $VERSION = '1.4';
|
| 116 |
rodolico |
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
|
| 117 |
rodolico |
22 |
# if they exist
|
| 20 |
rodolico |
23 |
|
| 2 |
rodolico |
24 |
sub cleanUp {
|
|
|
25 |
my ($delimiter, $text) = @_;
|
|
|
26 |
chomp $text;
|
| 117 |
rodolico |
27 |
if ( $delimiter && $text =~ m/[^$delimiter]*$delimiter\s*(.*)/ ) {
|
| 116 |
rodolico |
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 |
|
| 152 |
rodolico |
60 |
# simple function to return true if the current date is the first of the week, month or year
|
|
|
61 |
# parameter passed in is 'w' (weekly), 'm' (monthly) or 'y' (yearly)
|
|
|
62 |
# to have a test run only weekly, place
|
|
|
63 |
# exit 1 unless &checkDate( 'w' );
|
|
|
64 |
sub checkDate {
|
| 153 |
rodolico |
65 |
return 1 if -e '/tmp/sysinfo.firstrun';
|
| 152 |
rodolico |
66 |
my $frequency = lc shift;
|
|
|
67 |
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
|
|
68 |
return $mday == 1 if $frequency eq 'm'; # monthly
|
|
|
69 |
return $wday == 1 if $frequency eq 'w'; # weekly
|
|
|
70 |
return $yday == 1 if $frequency eq 'y'; # yearly
|
|
|
71 |
return 0; # we failed
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
|
| 20 |
rodolico |
75 |
1;
|