2013-08-06 124 views
0

该脚本每次都从命令行运行,但很少从cron作业运行。我可以这样运行:./chort.plLWP :: Simple和cron

但它与“错误值”的消息非常频繁(不总是)死亡,而从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); 
} 

回答

0

您可能需要使用LWP::UserAgent,它允许你控制的一个更高的水平。 LWP :: Simple有时太抽象,不知道出现问题时发生了什么。