为什么我的命令行不能从cron运行? [英] Why does my command-line not run from cron?

查看:186
本文介绍了为什么我的命令行不能从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

我使用完整的路径来消除工作目录中的问题。权限不应该是一个问题。

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或其他什么?

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?

推荐答案

这是通常,因为在cron下运行时没有获得完整的环境。最好的办法是使用以下命令捕获输出:

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

然后看看 / 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

这篇关于为什么我的命令行不能从cron运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆