Subversion Repositories camp_sysinfo_client_3

Rev

Rev 244 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#! /usr/bin/env perl

#    Program: save_local
#    Copyright (C) 2016  R. W. Rodolico
#
#    Description
#      Script will upload file passed on STDIN to URL defined in $server
#      using variable name $urlVarName.
#      Filename may also be passed on command line
#      It assumes the remote server will return the exact contents which
#      is then used to compare to what was sent
#      It will return the following codes
#        0 - success
#         1 - Could not find LWP::Simple module
#         2 - file not passed on STDIN
#         3 - Contents returned by server do not match our local copy
#         4 - URL call returned a "not found" error
#         5 - no key given for report contents
#         6 - no key given for report date
#         7 - no key given for hostname
#         8 - no key given for client
#         9 - no key given for serial number
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#    20200215 RWR
#    Modified it so it will create a filename containing report date, client name, machine name and serial number

use warnings;
use strict;

our $VERSION = '1.1.0';

use Data::Dumper;

sub writeFile {
   my ( $filename, $contents ) = @_;
   if ( open FILE,">$filename" ) {
      print FILE $contents;
      close FILE;
   } else {
      print "Could not write to $filename: $!";
      return 0;
   }
}

sub makeFileName {
   my $parameters = shift;
   my $filename = join( '_', ( $$parameters{'report date'}, $$parameters{'client name'}, $$parameters{'host name'}, $$parameters{'serial number'} ) );
   $filename .= '.sysinfo';
   return $filename;
}


sub doit {
   my ( $parameters, $message ) = @_;
   $$parameters{'output directory'} = '/tmp' unless $$parameters{'output directory'};
   `mkdir -p $$parameters{'output directory'}` unless -d $$parameters{'output directory'};
   $$parameters{'filename'} = &makeFileName( $parameters) unless $$parameters{'filename'};

   &writeFile( $$parameters{'output directory'} . '/' . $$parameters{'filename'}, $message ); # make a backup copy of the report
   return 1;
}

1;