#!/usr/bin/perl -w #use strict; #use File::stat; #use LWP::Simple; #two remote site response to check for header '200 OK' #local file to check for altered modification by an intruder' # explanation !! # i want to create a perl programme that will check for two link's header for '200 OK' response then use wget or any available resources to download a file, if file has been written then do nothing, BUT still keep checking on set interval basis for the two link header response. #if the 1st download link is not header response '200 OK' then report the error, remove the downloaded specified for the link down, and go for the second link header which must as well be '200 OK, else if on interval checked the two site specified headers are not '200 Ok' do nothing print my error or die.................Not Only that,t here is one more thing to check local file for altered modification' thats my confusion and am doing alot wrong.. am a newbie to perl want to go hard.....help me on this thank you #it seems not to be changing what to download and remove the unavailable.the next available rather it retains the first checked, like i said am newbie to perl so am just trying; my $whereto = $ARGV[0]; # This will be base directory of where to download my $filename = $whereto.'/'.$ARGV[1]; # the file name my $link1 = $ARGV[2]; # link 1 to check my $link2 = $ARGV[3]; # link 2 to check my $download = $ARGV[4]; #download for link 1 to write my $download2 = $ARGV[5]; #download for link 2 if link 1 not available my $sleep = $ARGV[6]; # sleep interval which i think can be the interval of time to recheck my $datetime = localtime; my $success = "\n [+] My downlod response Checker\n [-] Successfully ...\n [-] Process/PID : \n\n"; my $failed = "\n [?] perl sd.pl \n\n"; #perl sd.pl /usr/src/files a.c http://www.site1.eu/mytools/ww.c http://site2.com/mytools/a.c http://site1.com/mytools/a.c http://site2.com/mytools/a.c 10 if (@ARGV != 7) { print $failed; exit(); } else { print $success; } sub link2download { if ( -d $whereto ) { } else { system("mkdir $whereto"); } my $header1 = `curl -A "Mozilla Soldier" $link1 --head --silent` || `wget -SO- -T 5 -t 1 --user-agent="Mozilla Soldier" $link1 2>&1 | egrep "HTTP"`; my $header2 = `curl -A "Mozilla Soldier" $link2 --head --silent` || `wget -SO- -T 5 -t 1 --user-agent="Mozilla Soldier" $link2 2>&1 | egrep "HTTP"`; my $mod = (stat "$filename")[9]; my $ok = scalar localtime $mod; if ($ok eq "Mon Dec 10 18:30:55 2012" || $header1 !~ /200 OK/ && $header2 !~ /1.1 200 OK/){ #do nothinh } else{ if ($header1 =~ /200 OK/) { system("cd ".$whereto.";fetch ".$download.";wget ".$download.";curl -O ".$download.";lwp-download ".$download.";touch -t 201212101830.55 ".$filename.";"); }elsif ($header2 =~ /1.1 200 OK/) { system("cd ".$whereto.";fetch ".$download2.";wget ".$download2.";curl -O ".$download.";lwp-download ".$download.";touch -t 201212101830.55 ".$filename.";"); } elsif ($header1 !~ /200 OK/) { print "remote $link1 is down $datetime\n"; # then remove the downloaded system("cd ".$whereto.";rm -rf ".$filename.";"); } elsif ($header2 !~ /200 OK/) { print "remote $link2 is down $datetime\n"; system("cd ".$whereto.";rm -rf ".$filename.";"); } if ($header2 !~ /200/ && $header1 !~ /200 OK/) { die "$link1\n and $link2\n is down\n"; } print "Local $filename file altered Reloading .$datetime\n"; } } while (1) { sleep ($sleep); link2download(); print "interval\n\n"; # prints to screen }