logrotate.confのテスト

表題の通り。たまに書き加えたりした時に、間違えていて実行されないことがあるので確認する手段。

■ 環境

  • Linux

■ logrotate

下記のようなファイルで設定するとする。

$ cat /etc/logrotate.d/nginx
/var/log/nginx/*.log {
        daily
        dateext
        missingok
        rotate 7
        compress
        sharedscripts
        postrotate
                /sbin/service nginx reload > /dev/null 2>/dev/null || true
        endscript
}
$

これが正しく書かれているのか?を確認する。

$ logrotate -d /etc/logrotate.d/nginx
reading config file /etc/logrotate.d/nginx
reading config info for /var/log/nginx/*.log

Handling 1 logs

rotating pattern: /var/log/nginx/*.log  after 1 days (7 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/nginx/access.log
  log does not need rotating
considering log /var/log/nginx/error.log
  log does not need rotating
considering log /var/log/nginx/example.jp_access_443.log
  log does not need rotating
considering log /var/log/nginx/example.jp_access_80.log
  log does not need rotating
considering log /var/log/nginx/example.jp_error_443.log
  log does not need rotating
considering log /var/log/nginx/example.jp_error_80.log
  log does not need rotating
not running postrotate script, since no logs were rotated
$

試しにエラーを入れて実行してみる。

$ logrotate -d /etc/logrotate.d/nginx
reading config file /etc/logrotate.d/nginx
reading config info for /var/log/nginx/*.log
error: /etc/logrotate.d/nginx:5 unknown option 'rotata' -- ignoring line
error: /etc/logrotate.d/nginx:5 unexpected text

Handling 1 logs

rotating pattern: /var/log/nginx/*.log  after 1 days (no old logs will be kept)
empty log files are rotated, old logs are removed
  :
$

error“があることがわかる。また内容もわかる。

以上。