简体   繁体   English

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

[英]Manually running crontab cron.hourly returns missing file error

I've been trying my best to understand how crontab and logrotate work together, and I'm going around in circles.我一直在尽力了解 crontab 和 logrotate 如何协同工作,而且我一直在兜兜转转。
I have taken the line from /etc/crontab and run:我从 /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

The file logrotate does exist in /etc/cron.hourly:文件 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

I assume this is why my latest changes to rotate logs hourly is not working.我认为这就是为什么我对每小时轮换日志的最新更改不起作用的原因。

Oddly, when I run :奇怪的是,当我运行时:

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

It just hangs until I press ctrl+c to cancel it.它只是挂起,直到我按 ctrl+c 取消它。

My /etc/cron.hourly/logrotate looks like this:我的 /etc/cron.hourly/logrotate 看起来像这样:

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

If I run the following:如果我运行以下命令:

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

Then it rotates the logs exactly as it should.然后它会完全按照原样旋转日志。

This leads me to assume the error mentioned above is my issue.这使我认为上面提到的错误是我的问题。
Does anyone have any ideas they can give me as to what I've missed?有没有人对我错过的东西有任何想法可以给我? Cheers干杯

Update :更新
from what was recommended below, I converted my /etc/cron.hours/logrotate to unix line endings.根据下面推荐的内容,我将 /etc/cron.hours/logrotate 转换为 unix 行结尾。
This meant that running the crontab command manually in the terminal worked.这意味着在终端中手动运行 crontab 命令是有效的。 No errors, and logs were rotated correctly.没有错误,并且日志已正确轮换。

However crontab is still not running automatically.但是 crontab 仍然没有自动运行。

The answer here was during my deploy I had missed a file that had Windows line endings.这里的答案是在我部署期间我错过了一个带有 Windows 行结尾的文件。 Using dos2unix on the server it fixed everything.在服务器上使用 dos2unix 可以解决所有问题。

Running:跑步:

sudo service cron reload

Was required after editing "/etc/crontab" - thought I had read a few times this shouldn't be needed.编辑“/etc/crontab”后需要 - 以为我已经读了几次这不应该需要。

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

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