How to test a cron job?

谁说胖子不能爱 提交于 2019-12-22 10:00:03

问题


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


回答1:


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.

-Tony




回答2:


Cron should mail it results so it looks like you have a problem. Here, it seems you are missing a user to run the script as :

00,06,12,18 * * * user_name /opt/scripts/selenium/run_nis_inf_tests.sh

replace user_name by the name of the user the script needs to be run by, verify permissions of "run_nis_inf_tests.sh" and you should be ok.



来源:https://stackoverflow.com/questions/5837615/how-to-test-a-cron-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!