logrotate 手動工作,但在 Ubuntu 18.04 上無法透過 cron 自動工作

logrotate 手動工作,但在 Ubuntu 18.04 上無法透過 cron 自動工作

我有一個 logrotate 任務來輪換我的 nginx 日誌。我的設定檔位於 /etc/logrotate.d/nginx 中。當我運行時logrotate -f /etc/logrotate.d/nginx,它可以正確旋轉日誌,這意味著我的設定檔是正確的。

當我將命令放入 cron 時0 0 * * * logrotate -f /etc/logrotate.d/nginx,日誌不會輪換。雖然我可以CRON[6006]: (root) CMD (logrotate -f /etc/logrotate.d/nginx)在/var/log/cron.log中看到,這意味著該命令確實已經運行。有什麼不對的嗎?

這是我的 logrotate 設定檔:

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

/var/log/nginx/error.log {
    daily
    rotate 7
    compress
    copytruncate
    dateext
}

相關內容