linux debian crontab 作业未执行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5486601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:27:48  来源:igfitidea点击:

linux debian crontab job not executed

linuxdebiancrontab

提问by hornetbzz

I have a bash script foo.shlocated in the /etc/cron.dailydirectory, 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.

我有一个位于/etc/cron.daily目录中的 bash 脚本foo.sh,chmoded 700,由 root 拥有,root 用户的 crontab 列表与核心 Debian 安装保持不变(crontab -l)。我确实以不同于 crontab -l 和/或 crontab -e 的另一种方式运行 cronjob(例如,我没有按照特定 Debian 案例的建议使用 /etc/init.d/cron 重新启动 cron 守护进程)。尽管测试作业文件在类似条件下运行。该脚本经过调试,可以作为独立任务运行而不会返回错误。我还检查了日志 (/var/log/syslog),那里没有任何问题。

But: this particular job is not executed at all.

但是:这个特定的工作根本没有执行。

采纳答案by hornetbzz

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

哎呀。猜猜我找到了“为什么”或至少是“如何”:

Only renaming the job filename without ".sh" extensionsolved 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

解决方案:通过从其名称中删除所有.+字符来重命名您的脚本

回答by user237419

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 并且没有为运行部分指定 --lsbsysinit 选项(在这种情况下,'.' 将根据 LSB 分层和保留命名空间在 cron 脚本文件名中被接受)

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.

我希望我的评论可以帮助您了解真正的问题是什么。

回答by miklosq

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 sectionin the Debian Policy Manual.

之前给出的所有答案都很好,可以接受问题。但是,我相信我也应该添加我的观点以明确说明,Debian Linux 操作系统不支持包含.+字符的cron 作业文件名。请参阅相关章节Debian策略手册

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

所以这只是为了避免混淆,这不是一个错误。这就是 Debian 的工作方式。