Linux cronjob doesn't work (execute script)

雨燕双飞 提交于 2019-12-22 11:03:52

问题


I created a cronjob with the command crontab -e:

*/1 * * * * /var/lib/tomcat/webapps/ROOT/WEB-INF/scripts/test.sh 

This file test.sh should be executed every minute. But it doesn't work.

If I run the script manually it works fine. So I think the problem is the cronjob not the script ;)

Are there any permissions or something else which block the cronjob?

Is the cronjob syntax correct?

Thx


回答1:


For a start, you don't need the /1 if you want it done every minute. Just setting the minute field to * will do.

Next, you should place, as the first lines in your test script (though after the #! line if it's there):

env >/tmp/test.sh.dummy
set >>/tmp/test.sh.dummy

and see if that file shows up.

That will tell you if the script is running or not.

If it's not running, check to make sure cron itself is running:

pax> ps -ef | grep cron | grep -v grep
root      1048     1  0 08:45 ?        00:00:00 cron

(mine is).

If it is running, the most likely problem is that the environment under which cron runs your jobs is nowhere near the environment your shell gives you. Examine the differences between what was output to your /tmp/test.sh.dummy file and what your shell gives your when you execute env ; set.



来源:https://stackoverflow.com/questions/3483115/linux-cronjob-doesnt-work-execute-script

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