简体   繁体   English

linux debian crontab作业没有执行

[英]linux debian crontab job not executed

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. 我有一个bash脚本foo.sh位于/etc/cron.daily目录,chmoded 700,由root拥有,crontab列表为root用户不变(crontab -l)从核心Debian安装。 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). 我确实以不同于crontab -l和/或crontab -e的方式运行cronjob(例如,我没有按照特定的Debian案例中的/etc/init.d/cron重启cron守护进程)。 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. 我还检查了日志(/ var / log / syslog),没有任何错误。

But : this particular job is not executed at all. 但是 :这项特殊工作根本没有执行。

Oops. 哎呀。 Guess I found the "why" or at least, the "how" : 猜猜我发现了“为什么”或者至少是“如何”:

Only renaming the job filename without ".sh" extension solved that issue. 重命名没有“.sh”扩展名的作业文件名解决了这个问题。

I thought it was a Debian's bug but it isn't, as described in the other answers below. 我认为这是Debian的错误但不是,如下面的其他答案中所述。

SOLUTION: rename your script by removing all . 解决方案:通过删除全部来重命名脚本. or + characters from its name 或其名称中的+字符

the /etc/cron.daily scripts are executed by run-parts (see man 8 run-parts). /etc/cron.daily脚本由run-parts执行(参见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. 如果既没有给出--lsbsysinit选项也没有给出--regex选项,则名称必须完全由大写和小写字母,数字,下划线和连字符组成。

from /etc/crontab you can see that the daily cron jobs are being run with: 从/ etc / crontab你可以看到每天的cron作业正在运行:

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) debian不使用anacron,并且没有为run-parts指定--lsbsysinit选项(在这种情况下'。'将在cron脚本文件名中根据LSB层次结构和保留名称空间接受)

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: 无论如何,为了确保cron将运行您的脚本,您始终可以运行run-parts并检查您的脚本是否在run-parts输出中列出:

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. 我希望我的评论可以帮助您了解真正的问题。

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 . 但是,我相信我应该加上我的观点,以明确说明Debian Linux操作系统不支持包含的cron作业文件名. or + character. +字符。 See the relevant section in the Debian Policy Manual . 请参阅Debian Policy Manual中相关部分

So this is just to avoid confusion, that it's not a bug. 所以这只是为了避免混淆,这不是一个错误。 That's how Debian works. 这就是Debian的工作方式。

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

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