I have a list of arguments to pass into a perl script, using ARGV. The 4th argument, is a servername, but I want to pass it a text file with a list of servers called servers.txt. How do I pass that in and use it as an argument to ARGV?
Sample file 'servers.txt':
server1
server2
server3
Working code:
# usage example: ./test.pl Jul 05 2010 <server> <logfile>
# $ARGV[0]=Jul
# $ARGV[1]=05
# $ARGV[2]=2010
# $ARGV[3]=server
# $ARGV[4]=/pathoffile
use strict;
use warnings;
my($mon,$day,$year,$server,$file) = @ARGV;
open(my $fh,"ssh $server cat $file |") or die "can't open log $server:$file: $!\n";
while (my $line = <$fh>) {
if ($line =~ /.* $mon $day \d{2}:\d{2}:\d{2} $year:.*(ERROR:|backup-date=|backup-size=|backup-time=|backup-status)/) {
print $line;
}
}