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

查看:25
本文介绍了为什么我的命令行不能从 cron 运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 perl 脚本(属于 XMLTV 家族的grabbers",特别是tv_grab_oztivo).

我可以像这样成功运行它:

/sw/bin/perl/path/to/tv_grab_oztivo --output/path/to/tv.xml

我使用所有内容的完整路径来消除工作目录的问题.权限应该不是问题.

所以,如果我从终端 (Mac OSX) 运行它,它工作得很好.

但是当我将它设置为通过 cron 作业运行时,似乎什么也没发生.没有创建输出等.

就我所见,crontab 没有任何问题,因为如果我将 helloworld.pl 替换为实际脚本,它会在正确的时间运行得很好.

那么,我可以做些什么来调试?两种情况下看%ENV可以看出环境差异很大,但是还有什么方法可以调试呢?我怎样才能看到 cron 作业的输出,这可能是来自 shell 的某种 perl死"消息或未找到"消息或其他什么?

或者我应该尝试以某种方式为命令的 cron 版本提供与我一样运行时相同的环境?

解决方案

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

(/sw/bin/perl/path/to/tv_grab_oztivo ... ) >/tmp/qq 2>&1

然后看看/tmp/qq.

如果确实是缺少环境,那么您可能需要输入:

<预><代码>.~/.profile

或类似的东西,进入您的 cron 作业的执行链,例如:

( . ~/.profile ;/sw/bin/perl/path/to/tv_grab_oztivo ... ) >/tmp/qq 2>&1

I have a perl script (part of the XMLTV family of "grabbers", specifically tv_grab_oztivo).

I can successfully run it like this:

/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.

So, if I run it from the Terminal (Mac OSX) it works just fine.

But when I set it to run via a cron job, nothing appears to happen at all. No output is created etc.

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.

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?

Or should I be trying to somehow give the cron version of the command the same environment as when it's running as me?

解决方案

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

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

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天全站免登陆