Perl LWP::简单和cron
该脚本每次都从命令行运行,但很少从cron作业运行。我可以这样运行:Perl LWP::简单和cron,perl,cron,crontab,Perl,Cron,Crontab,该脚本每次都从命令行运行,但很少从cron作业运行。我可以这样运行:/chort.pl 但在从cron调用时,它经常(并非总是)以“错误的值”消息死亡: */2 10-18 * * 1-5 /path/to/chort.pl >> /tmp/chort.pl 2>&1 当它死亡时,$res为空打印“*$res*\n”打印**。因此,似乎在从cron调用时获取网页存在问题。 这里有一个片段: sub getLSEVal { my $fourWayKey
/chort.pl
但在从cron调用时,它经常(并非总是)以“错误的值”消息死亡:
*/2 10-18 * * 1-5 /path/to/chort.pl >> /tmp/chort.pl 2>&1
当它死亡时,$res
为空<代码>打印“*$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);
}
sub-getLSEVal
{
我的$fourWayKey=shift;
我的$url=”http://pat.to.url";
我的$res;
超时280=>sub{
$res=获取$url;
返回(-2,-2,-2);
};
打印$res;
$res=~/Price\| High\| Low.*?(.*?).*(.*?).*(.*?).*(.*?).*(.*?)/msig;
my$c=$1;
my$h=$2;
my$l=$3;
打印“$1$2$3\n”;
如果$c!~/\d+\.?\d*/或$h!~/\d+\.?\d*/或$l!~/\d+\.?\d*/,则为“错误值”;
回报($c、$h、$l);
}
您可能需要使用,这样可以实现更高级别的控制。LWP::Simple有时过于抽象,无法知道出现问题时发生了什么