develooper Front page | perl.beginners | Postings from March 2002

Re: time limit???

Thread Previous | Thread Next
From:
Peter Scott
Date:
March 29, 2002 11:54
Subject:
Re: time limit???
Message ID:
4.3.2.7.2.20020329114930.00aa7d70@shell2.webquarry.com
At 12:50 PM 3/29/02 -0500, Alberto Santana wrote:
>Hi guys,
>
>Suppose I have a Perl script (called from a crontab file) that will,
>basically, do something like this:
>
>$out=`lynx -dump http://lists.cpan.org/showlist.cgi?name=beginners`;
>open(OUT,">out");
>print OUT $out;
>close(OUT);
>$send_it=`mail me\@here.com<out`;
>
>OK, here comes the problem. What if the web page is down? lynx will
>keep trying for a while until it gives up or something.
>Is it possible to impose a time limit, like: execute $out, wait for
>45 seconds, if there was no response (lynx did not dump), exit(0);

Untested:

use LWP::UserAgent;
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;
$ua->timeout(45);
my $res = $ua->request(GET 
'http://lists.cpan.org/showlist.cgi?name=beginners');
if ($res->is_success) {
   require Mail::Send;
   my $msg = Mail::Send->new;
   $msg->to('me@here.com');
   my $fh = $msg->open;
   print $fh $res->content;
   $fh->close;
}


--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About