85 |
rodolico |
1 |
#! /usr/bin/env perl
|
|
|
2 |
|
|
|
3 |
# Program: save_local
|
|
|
4 |
# Copyright (C) 2016 R. W. Rodolico
|
|
|
5 |
#
|
|
|
6 |
# Description
|
|
|
7 |
# Script will upload file passed on STDIN to URL defined in $server
|
|
|
8 |
# using variable name $urlVarName.
|
|
|
9 |
# Filename may also be passed on command line
|
|
|
10 |
# It assumes the remote server will return the exact contents which
|
|
|
11 |
# is then used to compare to what was sent
|
|
|
12 |
# It will return the following codes
|
|
|
13 |
# 0 - success
|
|
|
14 |
# 1 - Could not find LWP::Simple module
|
|
|
15 |
# 2 - file not passed on STDIN
|
|
|
16 |
# 3 - Contents returned by server do not match our local copy
|
|
|
17 |
# 4 - URL call returned a "not found" error
|
|
|
18 |
# 5 - no key given for report contents
|
|
|
19 |
# 6 - no key given for report date
|
|
|
20 |
# 7 - no key given for hostname
|
|
|
21 |
# 8 - no key given for client
|
|
|
22 |
# 9 - no key given for serial number
|
|
|
23 |
#
|
|
|
24 |
# This program is free software: you can redistribute it and/or modify
|
|
|
25 |
# it under the terms of the GNU General Public License as published by
|
|
|
26 |
# the Free Software Foundation, either version 3 of the License, or
|
|
|
27 |
# (at your option) any later version.
|
|
|
28 |
#
|
|
|
29 |
# This program is distributed in the hope that it will be useful,
|
|
|
30 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
31 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
32 |
# GNU General Public License for more details.
|
|
|
33 |
#
|
|
|
34 |
# You should have received a copy of the GNU General Public License
|
|
|
35 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
154 |
rodolico |
36 |
#
|
|
|
37 |
# 20200215 RWR
|
|
|
38 |
# Modified it so it will create a filename containing report date, client name, machine name and serial number
|
85 |
rodolico |
39 |
|
|
|
40 |
use warnings;
|
|
|
41 |
use strict;
|
|
|
42 |
|
154 |
rodolico |
43 |
our $VERSION = '1.1.0';
|
85 |
rodolico |
44 |
|
|
|
45 |
use Data::Dumper;
|
|
|
46 |
|
|
|
47 |
sub writeFile {
|
|
|
48 |
my ( $filename, $contents ) = @_;
|
|
|
49 |
if ( open FILE,">$filename" ) {
|
|
|
50 |
print FILE $contents;
|
|
|
51 |
close FILE;
|
|
|
52 |
} else {
|
|
|
53 |
print "Could not write to $filename: $!";
|
|
|
54 |
return 0;
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
154 |
rodolico |
58 |
sub makeFileName {
|
|
|
59 |
my $parameters = shift;
|
|
|
60 |
my $filename = join( '_', ( $$parameters{'report date'}, $$parameters{'client name'}, $$parameters{'host name'}, $$parameters{'serial number'} ) );
|
|
|
61 |
$filename .= '.sysinfo';
|
|
|
62 |
return $filename;
|
85 |
rodolico |
63 |
}
|
|
|
64 |
|
154 |
rodolico |
65 |
|
85 |
rodolico |
66 |
sub doit {
|
|
|
67 |
my ( $parameters, $message ) = @_;
|
|
|
68 |
$$parameters{'output directory'} = '/tmp' unless $$parameters{'output directory'};
|
154 |
rodolico |
69 |
`mkdir -p $$parameters{'output directory'}` unless -d $$parameters{'output directory'};
|
|
|
70 |
$$parameters{'filename'} = &makeFileName( $parameters) unless $$parameters{'filename'};
|
85 |
rodolico |
71 |
|
154 |
rodolico |
72 |
&writeFile( $$parameters{'output directory'} . '/' . $$parameters{'filename'}, $message ); # make a backup copy of the report
|
85 |
rodolico |
73 |
return 1;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
1;
|
|
|
77 |
|
|
|
78 |
|