[英]LWP::Simple and cron
該腳本每次都可從命令行運行,但很少通過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);
}
您可能需要使用LWP :: UserAgent ,它允許您進行更高級別的控制。 LWP :: Simple有時過於抽象,無法知道問題出現時發生的情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.