这个脚本每次从命令行运行,但很少从cron作业中运行。我可以这样运行:./chort.pl
但是,在从cron调用它时,它经常(并不总是)带有“错误值”消息而死:
*/2 10-18 * * 1-5 /path/to/chort.pl >> /tmp/chort.pl 2>&1当它死的时候,$res是空的。print "*$res*\n";打印**。因此,似乎,在从cron调用时获取网页存在问题。这里有一个片段:
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);
}发布于 2013-08-06 10:49:02
您可能需要使用LWP::UserAgent,这允许您进行更高级别的控制。LWP::简单有时太抽象,不知道问题出现时会发生什么。
https://stackoverflow.com/questions/18077166
复制相似问题