You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 18.04环境下logrotate手动执行正常但cron自动执行失败问题排查求助

Ubuntu 18.04环境下logrotate手动执行正常但cron自动执行失败问题排查求助

各位好,我在Ubuntu 18.04上给nginx日志配置了logrotate轮转任务,配置文件放在/etc/logrotate.d/nginx里。手动执行logrotate -f /etc/logrotate.d/nginx的时候,日志能正常完成轮转,这说明我的配置文件应该是没问题的。

但当我把这个命令加到cron定时任务里,设置成0 0 * * * logrotate -f /etc/logrotate.d/nginx之后,日志却没有被轮转。我查看了/var/log/cron.log,能看到类似CRON[6006]: (root) CMD (logrotate -f /etc/logrotate.d/nginx)的记录,证明cron确实已经执行了这条命令,可就是没达到预期效果,有没有大佬能帮我排查下问题出在哪?

附上我的logrotate配置文件内容:

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

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

备注:内容来源于stack exchange,提问作者Hank Chow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 12:17:40