为什么我的命令行不是从cron运行的?
我有一个perl脚本(属于 XMLTV 系列的抓取工具 ,特别是 tv_grab_oztivo
)。
I have a perl script (part of the XMLTV family of "grabbers", specifically tv_grab_oztivo
).
我可以这样成功运行:
/sw/bin/perl /path/to/tv_grab_oztivo --output /path/to/tv.xml
$ b b
我使用完整路径来消除工作目录中的问题。权限不应该是一个问题。
I use the full paths to everything to eliminate issues with the Working Directory. Permissions shouldn't be a problem.
所以,如果我从终端(Mac OSX)运行它的工作正常。
So, if I run it from the Terminal (Mac OSX) it works just fine.
但是当我将其设置为通过cron作业运行时,没有任何事情发生。没有输出创建等。
But when I set it to run via a cron job, nothing appears to happen at all. No output is created etc.
crontab没有什么问题,只要我看到,因为如果我替换helloworld.pl的实际脚本,它在正确的时间运行正常。
There isn't anything wrong with the crontab as far as I can see, because if I substitute a helloworld.pl for the actual script, it runs just fine at the right time.
那么,我能做什么来调试?在这两种情况下,我可以从%ENV
看到环境是非常不同的,但是我可以采取什么其他方法来调试?如何查看cron作业的输出,这可能是shell或任何其他类型的perldie消息或not found消息?
So, what can I do to debug? I can see from looking at %ENV
in the two cases that the environment is very different, but what other approaches can I take to debugging? How can I see the output of the cron job, which might be some kind of perl "die" message or "not found" message from the shell or whatever?
我应该试图以某种方式给予cron版本的命令与当它作为我运行时相同的环境。
Or should I be trying to somehow give the cron version of the command the same environment as when it's running as me?
em> ,因为在cron下运行时,您无法获得完整的环境。最好的办法是使用命令捕获ouput:
It's often because you don't get the full environment when running under cron. Best bet is to capture the ouput by using the command:
( /sw/bin/perl /path/to/tv_grab_oztivo ... ) >/tmp/qq 2>&1
code> / tmp / qq 。
and then have a look at /tmp/qq
.
如果它确实是一个缺少的环境,那么你可能需要:
If it does turn out to be a missing environment, then you may need to put:
. ~/.profile
或类似的东西插入到cron作业的执行链中,例如: / p>
or something similar, into the execution chain of your cron job, such as:
( . ~/.profile ; /sw/bin/perl /path/to/tv_grab_oztivo ... ) >/tmp/qq 2>&1