linux debian crontab job not executed

ぐ巨炮叔叔 提交于 2019-11-27 03:36:44

问题


I have a bash script foo.sh located in the /etc/cron.daily directory, chmoded 700, owned by root, crontab list for the root user is unchanged (crontab -l) from the core Debian installation. I did run cronjob in another way than crontab -l and/or crontab -e (eg I did not restart cron daemon with /etc/init.d/cron as adviced in the specific Debian's case). Despite a test job file is running under similar conditions. The script is debugged and can be run as a standalone task without returning errors. I've also checked logs (/var/log/syslog) and nothing wrong in there.

But: this particular job is not executed at all.


回答1:


Oops. Guess I found the "why" or at least, the "how" :

Only renaming the job filename without ".sh" extension solved that issue.

I thought it was a Debian's bug but it isn't, as described in the other answers below.

SOLUTION: rename your script by removing all . or + characters from its name




回答2:


the /etc/cron.daily scripts are executed by run-parts (see man 8 run-parts).

there you go with a snip from the manpage:

If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of upper and lower case letters, digits, underscores, and hyphens.

from /etc/crontab you can see that the daily cron jobs are being run with:

25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

debian doesn't use anacron and there's no --lsbsysinit option specified for run-parts (in that case '.' will be accepted in the cron script filename as per the LSB hierarchical and reserved namespaces)

anyway, to make sure cron will run your script you can always run run-parts and check that your script is listed in the run-parts output:

run-parts --test /etc/cron.daily

or

run-parts --list /etc/cron.daily

I hope my comment helps you understand what the real problem was.




回答3:


All the answers given before are good and acceptable to the question. However, I believe I should add my point as well to make it clear, that Debian Linux OS does not support cron job filenames that include the . or + character. See the relevant section in the Debian Policy Manual.

So this is just to avoid confusion, that it's not a bug. That's how Debian works.



来源:https://stackoverflow.com/questions/5486601/linux-debian-crontab-job-not-executed

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