Hi,
I am so confused. I created a small script to download some files from a server. These are configs visible in webpages. We need to automatically backup over time and from several servers while just HTTP access is possible.
Now I have a code where I check whether I can get a response from server in a reasonable time (accessibility check). I want this done for all html pages I specify in file. I got a foreach loop that does it. But that just don't work and asks only first item of an array. If i copy-paste the same foreach code second time, the firs loop works a expected while second again asks just the first item of the array. Here the code. Please help.
#!/usr/bin/perl
use strict;
use Switch;
my $i;
my $arguments;
my $date;
my $curla;
my @args;
my @links;
my $response;
my $part;
my $curlc;
my $time;
sub check_link($) {
my $link=$_[0];
my $page="NOK";
$link =~ s/\n//g;
$link =~ s/\r//g;
print LOG "check_link: checking validity of $link\n";
my $curlc="curl ".$curla." ".$link."\n";
print LOG "check_link: getting page with $curlc";
local $SIG{ALRM} = sub {
print LOG "check_link: no response - timing out\n";
`pkill -9 -f $link`;
$page="NOK";
};
alarm(10000);
$page=`$curlc`;
alarm(0);
print LOG "check_link: got response in time\n";
return $page;
}
open (LOG,">>rapget.log") or die "can't open logfile\n";
$date=`date`;
print LOG "$$: ============================\nnew start of script : $da
+te\n";
foreach $i(@ARGV){
if($i=~/-/){$arguments.=$i." "};
if($i!~/-/){$arguments.=$i."%"};
}
print LOG "$$:ARGUMENTS : $arguments\n";
@args= split (/%/,$arguments);
foreach $i(@args){
switch ($i) {
case /-U.*/ {print LOG "Adding user to curl\n";$curla.
+=$i." ";}
case /-x.*/ {print LOG "Using proxy for curl\n";$curla
+.=$i." ";}
else {print LOG "Unknown argument: $i\n"}
}
}
print LOG "$$:curla=$curla\n";
open (IN,"<linklist.txt") or die "no input file found\n";
@links=<IN>;
close(IN);
my $link;
foreach $link(@links) {
chomp($link);
$response=check_link("$link");
$part = $response;
$part =~ s/\r//g;
$part =~ s/\n//g;
print "1 Empty run\n";
}