[英]LWP::Simple and cron
This script works every time from command line but very rarely from cron job. 该脚本每次都可从命令行运行,但很少通过cron作业运行。 I can run it like this:
./chort.pl
我可以这样运行:
./chort.pl
But it dies very frequently (not always) with "wrong values" message while calling it from cron: 但是在从cron调用它时,它经常(并非总是)死于“错误值”消息:
*/2 10-18 * * 1-5 /path/to/chort.pl >> /tmp/chort.pl 2>&1
When it dies, than the $res
is empty. 它死后,
$res
为空。 print "*$res*\\n";
prints **
. 打印
**
。 So , it seems, that there is a problem with getting of webpage while calling from cron. 因此,似乎从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);
}
You probably need to use LWP::UserAgent , which allows you a higher level of control. 您可能需要使用LWP :: UserAgent ,它允许您进行更高级别的控制。 LWP::Simple sometimes is too abstract to know what is happening when a problem appears.
LWP :: Simple有时过于抽象,无法知道问题出现时发生的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.