Score:0

logrotate works manually but not works automatically via cron on Ubuntu 18.04

cn flag

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
}
in flag
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.
Hank Chow avatar
cn flag
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
in flag
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)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.