linux debian crontab 作业未执行
我有一个bash脚本foo.sh位于/etc/cron.daily目录中,chmoded 700,由root拥有,root用户的crontab列表未更改(crontab -l) 来自 Debian 核心安装。我确实以不同于 crontab -l 和/或 crontab -e 的方式运行 cronjob (例如,我没有按照特定 Debian 情况下的建议使用 /etc/init.d/cron 重新启动 cron 守护进程)。尽管测试作业文件正在类似的条件下运行。该脚本经过调试,可以作为独立任务运行而不会返回错误。我还检查了日志(/var/log/syslog),里面没有任何问题。
但是:这个特定的作业根本没有执行。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
哎呀。我想我找到了“为什么”,或者至少找到了“如何”:
只有重命名不带“.sh”扩展名的作业文件名解决了这个问题。
我以为这是 Debian 的错误,但事实并非如此,如下面其他答案所述。
解决方案:通过从名称中删除所有
.
或+
字符来重命名脚本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/etc/cron.daily 脚本由 run-parts 执行(参见 man 8 run-parts)。
您可以从联机帮助页中摘取一段内容:
从 /etc/crontab 你可以看到每日 cron 作业正在运行:
debian 不使用 anacron 并且没有为运行部分指定 --lsbsysinit 选项(在这种情况下, cron 脚本将接受 '.'文件名按照 LSB 层次结构和保留命名空间)
无论如何,为了确保 cron 将运行您的脚本,您可以随时运行 run-parts 并检查您的脚本是否在 run-parts 输出中列出:
或者
我希望我的评论可以帮助您了解什么真正的问题是。
the /etc/cron.daily scripts are executed by run-parts (see man 8 run-parts).
there you go with a snip from the manpage:
from /etc/crontab you can see that the daily cron jobs are being run with:
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:
or
I hope my comment helps you understand what the real problem was.
之前给出的所有答案都很好并且可以接受该问题。但是,我认为我还应该添加我的观点以明确说明,Debian Linux 操作系统不支持包含
.
或+
字符的 cron 作业文件名。请参阅 相关部分 a href="http://www.debian.org/doc/debian-policy/" rel="nofollow">Debian 政策手册。所以这只是为了避免混淆,这不是一个错误。这就是 Debian 的工作原理。
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.