0

I have a logrotate task to rotate my nginx logs. I have my config file in /etc/logrotate.d/nginx. When I run logrotate -f /etc/logrotate.d/nginx, it can rotate the logs correctly, which means my config file is corrent.

By when I put the command in cron like 0 0 * * * logrotate -f /etc/logrotate.d/nginx, the logs are not rotated. Although I can see CRON[6006]: (root) CMD (logrotate -f /etc/logrotate.d/nginx) in /var/log/cron.log, which means the command does have been run. Is there anything wrong?

Here's my logrotate config file:

/var/log/nginx/access.log {
    daily
    rotate 3
    compress
    copytruncate
    dateext
}

/var/log/nginx/error.log {
    daily
    rotate 7
    compress
    copytruncate
    dateext
}
Hank Chow
  • 111
  • 2
  • Why do you add it manually to cron in the first place? Just adding the config to logrotate should be enough for logrotate to handle it during its regular run. – Gerald Schneider Feb 20 '23 at 06:29
  • Maybe it's better to let logrotate itself to handle it during its regular run. But I think it won't make any conflict if I set the logrotate task in cron. @GeraldSchneider – Hank Chow Feb 20 '23 at 06:37
  • Does this answer your question? [Why is my crontab not working, and how can I troubleshoot it?](https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it) – Gerald Schneider Feb 20 '23 at 06:40

0 Answers0