简体   繁体   English

Cron 作业神秘地停止运行?

[英]Cron job mysteriously stopped running?

I have a cron job on an Ubuntu 10.4 server that stopped running for no apparent reason.我在 Ubuntu 10.4 服务器上有一个没有明显原因停止运行的 cron 作业。 (The job ran for months and has not been changed.) I am not a *nix guru so I plead ignorance if this is a simple problem. (这项工作已经运行了几个月,一直没有改变。)我不是 *nix 大师,所以如果这是一个简单的问题,我恳求无知。 I can't find any reason or indication why this job would have stopped.我找不到任何原因或迹象表明为什么这项工作会停止。 I've restarted the server without success.我重新启动了服务器但没有成功。 Here's the job:这是工作:

# m h  dom mon dow   command
0 * * * * java -jar /home/mydir/myjar.jar >>/home/mydir/crontaboutput.txt

The last line in the output file shows that the program ran on 8/29/2012.输出文件中的最后一行显示该程序于 2012 年 8 月 29 日运行。 Nothing after that.之后就什么都没有了。

Any ideas where to look?任何想法在哪里看?

There should be something in your system log when the job was run. 运行作业时,系统日志中应该有一些内容。 The other thing you could >try is to add 2>&1 to the job to see any errors in your text file. 您可以>尝试的另一件事是在作业中添加2>&1以查看文本文件中的任何错误。 – Lars Kotthoff yesterday - 昨天Lars Kotthoff

This proved to be the key piece of information - adding 2>&1 allowed me to capture an error that wasn't getting reported anywhere else. 这被证明是关键的信息 - 添加2>&1允许我捕获一个没有在其他地方报告的错误。 The completed command line then looked like: 完成的命令行然后看起来像:

java -jar /home/mydir/myjar.jar  2>&1  >>/home/mydir/crontaboutput.txt

Perhaps your cron daemon has stopped, or changed configuration (ie /etc/cron.deny ). 也许您的cron守护程序已停止或更改配置(即/etc/cron.deny )。 I suggest to make a shell script, and running it from crontab . 我建议制作一个shell脚本,然后从crontab运行它。 I also suggest to run thru your crontab some other program (just for testing) at some other time. 我还建议在其他时间运行你的crontab一些其他程序(仅用于测试)。 You can use the logger command in your shell script for syslog . 您可以在shell脚本中使用logger命令来进行syslog Look into system log files. 查看系统日志文件。

Accepted answer is correct, (ie, check the error logs) which pointed out the error in my case.接受的答案是正确的,(即检查错误日志)在我的案例中指出了错误。 Besides check for the following issues除了检查以下问题

  1. include('../my_dir/my_file.php) may work from url but it will not work when cron job is run, will spit out error. include('../my_dir/my_file.php) 可以从 url 工作,但是当运行 cron 作业时它不起作用,会吐出错误。

  2. $_SERVER variables does not work inside cron os if you are using $_SERVER['DOCUMENT_ROOT'], it will not be recognized and you will have an error in the cron job.如果您使用 $_SERVER['DOCUMENT_ROOT'],$_SERVER 变量在 cron 操作系统中不起作用,它不会被识别并且您将在 cron 作业中出错。

Make sure to test the cron and have it run, send an email etc to make sure it is run.确保测试 cron 并让它运行,发送电子邮件等以确保它运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM