如何测试 cron 作业? [英] How to test a cron job?
问题描述
我使用的是 Ubuntu Linux 10.0.4.我想每天每 6 小时运行一次脚本.当我发出 sudo crontab -e
时,我看到:
I'm using Ubuntu Linux 10.0.4. I want to run a script every 6 hours, every day. When I issue sudo crontab -e
, I see:
# m h dom mon dow command
* 00,06,12,18 * * * /opt/scripts/selenium/run_nis_inf_tests.sh
但是,我没有从我的脚本中看到预期的结果,我什至不确定它是否正在运行.有没有一种方法可以测试脚本是否正常运行,而不是等到指定的时间.或者,如何查看脚本生成的错误?- 戴夫
However, I'm not seeing the expected outcome from my script, and I'm not even sure if its running. Is there a way to test, short of waiting until the specified time, that the script is running properly. Or, how can I view the errors the script is generating? - Dave
推荐答案
您可以将 MAILTO 变量更新为您的电子邮件地址,并且 cron 应该通过电子邮件向您发送任何 STDOUT 和 STDERR 输出.还要检查您的 syslog 文件/var/log/messages 以查看脚本是否正在由 cron 执行.
You can update the MAILTO variable to your email address, and cron should email you any STDOUT and STDERR output. Also check your syslog file /var/log/messages to see if the script is being executed by cron.
-托尼
这篇关于如何测试 cron 作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!