简体   繁体   中英

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.
I have taken the line from /etc/crontab and run:

$ 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:

$ 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.

My /etc/cron.hourly/logrotate looks like this:

#!/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.
This meant that running the crontab command manually in the terminal worked. No errors, and logs were rotated correctly.

However crontab is still not running automatically.

The answer here was during my deploy I had missed a file that had Windows line endings. Using dos2unix on the server it fixed everything.

Running:

sudo service cron reload

Was required after editing "/etc/crontab" - thought I had read a few times this shouldn't be needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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