我在CentOS 6上configuration了lograotate。当我手动运行它时,它工作正常,但是使用CRON它不起作用。 克朗在其日志中说:“一切都好,我运行你的命令”,但没有任何反应。 细节:
cat /etc/logrotate.d/myproject
/var/opt/myproject/log/error.log { size=200M rotate 25 missingok notifempty copytruncate nocreate nocompress nodateext }
猫/etc/cron.d/1everymin
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ * * * * * root /etc/cron.min/logrotate
cat /etc/cron.min/logrotate
#!/bin/sh #/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1 /usr/sbin/logrotate -v /etc/logrotate.conf > /logrotate.log EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0
每分钟我都会在/ var / log / cron中看到
Jan 16 21:40:01 localhost CROND[31541]: (root) CMD (/etc/cron.min/logrotate) Jan 16 21:41:01 localhost CROND[31552]: (root) CMD (/etc/cron.min/logrotate) Jan 16 21:42:01 localhost CROND[31561]: (root) CMD (/etc/cron.min/logrotate) Jan 16 21:43:01 localhost CROND[31575]: (root) CMD (/etc/cron.min/logrotate) Jan 16 21:44:01 localhost CROND[31587]: (root) CMD (/etc/cron.min/logrotate)
但是日志实际上是不旋转的:没有任何反应,/logrotate.log是空的
如果我手动执行/etc/cron.min/logrotate所有工作正常,/logrotate.log有关于日志旋转的信息
如果启用SELinux,cron将不被允许写入/要查看是否启用,请使用:
getenforce
尝试暂时login其他地方,如/var/log/logrotate.log
假定启用了auditd,请确保在/var/log/audit/auditd.log中查找拒绝。