#!/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 hea +der 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 n +othing 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 h +ard.....help me on this thank you #it seems not to be changing what to download and remove the unavaila +ble.the next available rather it retains the first checked, like i sa +id am newbie to perl so am just trying; my $whereto = $ARGV[0]; # This will be base directory of where to dow +nload 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 interv +al 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 <Dir> <file.exention> <link 1> <lin +k 2> <download for link 1> <download for link 2> <check interval>\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` || `w +get -SO- -T 5 -t 1 --user-agent="Mozilla Soldier" $link1 2>&1 | egrep + "HTTP"`; my $header2 = `curl -A "Mozilla Soldier" $link2 --head --silent` || `w +get -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/ && $hea +der2 !~ /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 downloa +ded 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 }
The beginning of knowledge is the discovery of something we do not understand.
    Frank Herbert (1920 - 1986)

In reply to Re^4: Loop walkthrough by beanscake
in thread Loop walkthrough by beanscake

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.