手动运行crontab cron.hourly返回丢失的文件错误

时间:2019-06-26 13:53:05

标签: linux ubuntu cron logrotate

我一直在尽力了解crontab和logrotate如何一起工作,并且我正在圈子中闲逛。
我已从/ etc / crontab中提取并运行:

$ sudo run-parts --report /etc/cron.hourly
/etc/cron.hourly/logrotate:
run-parts: failed to exec /etc/cron.hourly/logrotate: No such file or directory
run-parts: /etc/cron.hourly/logrotate exited with return code 1

$ run-parts --report /etc/cron.hourly
/etc/cron.hourly/logrotate:
run-parts: failed to exec /etc/cron.hourly/logrotate: No such file or directory
run-parts: /etc/cron.hourly/logrotate exited with return code 1

logrotate文件确实存在于/etc/cron.hourly中:

$ ll /etc/cron.hourly/
total 16
drwxr-xr-x  2 root root 4096 Jun 25 15:43 ./
drwxr-xr-x 94 root root 4096 Jun 26 10:20 ../
-rwxrwxr-x  1 root root   98 Jun 26 13:00 logrotate*
-rw-r--r--  1 root root  102 Feb  9  2013 .placeholder

我认为这就是为什么我最新的每小时轮换日志更改无法正常工作的原因。

奇怪的是,当我跑步时:

$ sudo run-parts --report /etc/cron.daily

它只是挂起,直到我按ctrl + c取消它为止。

我的/etc/cron.hourly/logrotate看起来像这样:

#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate_hourly.conf

如果我运行以下命令:

sudo /usr/sbin/logrotate /etc/logrotate_hourly.conf

然后它完全按照原样旋转日志。

这使我假设上述错误是我的问题。
有人对我错过的事情有什么想法可以给我吗? 干杯

更新
从下面的建议中,我将/etc/cron.hours/logrotate转换为unix行结尾。
这意味着可以在终端中手动运行crontab命令。没有错误,日志已正确轮换。

但是crontab仍然没有自动运行。

1 个答案:

答案 0 :(得分:0)

这里的答案是在我部署期间,我错过了一个带有Windows行尾的文件。在服务器上使用dos2unix可以修复所有问题。

运行:

sudo service cron reload

在编辑“ / etc / crontab”之后是必需的-以为我已经读过几次了,所以不需要。