I have the following perl script that works locally given the input parameters.
I need the script to access remote servers for the same information, given that I’ve already setup the ssh keys successfully. The path for the logfiles on the remote servers are identical to local. Configuration for remote servers are identical. I just need to run across multiple servers and bring back the data either to terminal or on a file. Do I need to put this in a shell script?
# usage example: <this script> Jun 26 2010 <logfile>
use strict;
use warnings;
my ($mon,$day,$year) = ($ARGV[0],$ARGV[1],$ARGV[2]);
open(FH,"< $ARGV[3]") or die "can't open log file $ARGV[3]: $!\n";
while (my $line = <FH>) {
if ($line =~ /.* $mon $day \d{2}:\d{2}:\d{2} $year:.*(ERROR:|backup-date=|host=|backup-size=|backup-time=|backup-status)/) {
print $line;
}
}
You could modify the script to take the server name as an extra argument.
My version takes advantage of the fact that the Perl
openfunction can ‘open’ a command and the output from the command is presented as input to your script.—- edit
Regarding your follow-up question, if the file exists in the same place on a number of hosts then you could swap the argument order around and pass the list of hosts on the command-line: