web-dev-qa-db-ja.com

logrotateが自動的に実行されないのはなぜですか?

特定のトラフィックを異なるファイルに分割するために、いくつかのフィルターを備えた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

# m h 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も失敗しますか?

2
John K.

これは修正されたようです。 syslog-ngファイルlogrotate -d /etc/logrotate.confの代わりにconfファイルでlogrotateを実行しようとしましたが、このエラーがスローされていましたIgnoring /etc/logrotate.conf because of bad file mode.クイック検索を実行し、ファイル許可が原因であることがわかりました。ファイルSudo chmod 644 /etc/logrotate.confのパーミッションを変更し、/ etc/crontabの毎日の時間を変更してテストを実行しました。

その後、ファイルは自動的にローテーションされました。これが修正されたようです。助けてくれてありがとう。

5
John K.