为什么logrotate不会自动运行?

我已经设置了一个带有一些filter的Syslog-ng服务器,以将某些流量分成不同的文件。 我修改了位于/etc/logrotate.d/syslog-ng的logrotate文件,以便每天轮换这些文件,但是logrotate没有按预期运行。 我必须使用sudo logrotate -f /etc/logrotate.d/syslog-ng手动旋转日志

我找不到它不能自动运行的原因。

/etc/logrotate.d/syslog-ng文件的内容(我添加的部分是最顶部的块):

 /var/log/wlc /var/log/userid /var/log/cltolt040 /var/log/ise /var/log/vg /var/log/firewall /var/log/steelhead /var/log/syslog /var/log/f5 /var/log/switch /var/log/router { su root root rotate 14 create 0755 ics ics daily missingok notifempty compress postrotate invoke-rc.d syslog-ng reload > /dev/null endscript } /var/log/mail.info /var/log/mail.warn /var/log/mail.err /var/log/mail.log /var/log/daemon.log /var/log/kern.log /var/log/auth.log /var/log/user.log /var/log/lpr.log /var/log/cron.log /var/log/debug /var/log/messages /var/log/error { rotate 4 weekly missingok notifempty compress delaycompress sharedscripts postrotate invoke-rc.d syslog-ng reload > /dev/null endscript } 

crontab的内容:

 # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # mh dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) 

/etc/cron.daily/logrotate的内容:

 #!/bin/sh # Clean non existent log file entries from status file cd /var/lib/logrotate test -e status || touch status head -1 status > status.clean sed 's/"//g' status | while read logfile date do [ -e "$logfile" ] && echo "\"$logfile\" $date" done >> status.clean mv status.clean status test -x /usr/sbin/logrotate || exit 0 /usr/sbin/logrotate /etc/logrotate.conf 

我当时认为它可能是一个权限问题,但如果是这样的情况下不会运行logrotate -f也会失败?

看起来我修好了。 我试图在conf文件上运行logrotate而不是syslog-ng文件, logrotate -d /etc/logrotate.confIgnoring /etc/logrotate.conf because of bad file mode. 快速搜索并发现这可能是因为文件权限。 我更改了文件sudo chmod 644 /etc/logrotate.conf权限,并通过更改/ etc / crontab中的每日时间来运行测试。

然后自动旋转文件。 所以看起来这就是修复。 谢谢您的帮助。