Tuesday, 6 August 2013

LWP::Simle and cron

LWP::Simle and cron

This script works every time from command line but very rarely from cron
job. I can run it like this: ./chort.pl
But it dies very frequently (not always) with "wrong values" message while
calling it from cron:
*/2 10-18 * * 1-5 /path/to/chort.pl >> /tmp/chort.pl 2>&1
When it dies, than the $res is empty. So , it seems, that there is a
problem with getting of webpage while calling from cron. Here a snippet:
sub getLSEVal
{
my $fourWayKey = shift;
my $url = "http://pat.to.url";
my $res;
timeout 280 => sub {
$res = get $url ;
return (-2, -2, -2 );
};
print $res;
$res =~ /Price\| High \| Low .*?<tr
class="odd">.*?<td>(.*?)<\/td>.*?<td>(.*?)<\/td>.*?<td>(.*?)<\/td>/msig;
my $c = $1;
my $h = $2;
my $l = $3;
print "$1 $2 $3\n";
die ("wrong values") if $c !~ /\d+\.?\d*/ or $h !~ /\d+\.?\d*/ or
$l !~ /\d+\.?\d*/;
return ($c, $h, $l);
}

No comments:

Post a Comment