如何检查 logrotate 语法?

如何检查 logrotate 语法?

我们怀疑 /etc/logrotate.d/FOO 文件中存在拼写错误。

我们如何检查呢?到目前为止我可以看到:

https://linux.die.net/man/8/logrotate

也许是这个?:

logrotate -df /etc/logrotate.d/FOO 2>&1 | grep -i error

答案1

我同意弗拉德对当前答案的评论。安全的方法只需检查语法而不实际旋转任何内容是使用调试选项。

man logrotate

       -d, --debug
              Turns  on  debug  mode  and implies -v.  In
              debug mode, no changes will be made to  the
              logs or to the logrotate state file.

我的机器上的示例:

$ logrotate -d /etc/logrotate.d/httpd 
reading config file /etc/logrotate.d/httpd

Handling 1 logs

rotating pattern: /var/log/httpd/*_log  5242880 bytes (10 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/httpd/access_log
  log does not need rotating
considering log /var/log/httpd/error_log
  log does not need rotating
not running postrotate script, since no logs were rotated

添加该-f选项将强制旋转实际执行的(无论是否需要),允许进一步分析。

概括:

-d    Just debug, don't actually rotate.
-df   Actually perform rotation and debug (includes verify).
-vf   Actually perform rotation and just verify.

答案2

logrotate 语法可以在之前使用标志 -v 进行验证

logrotate -vf /etc/logrotate.d/FOO

如果轮换文件出现错误,则应该显示该错误。

相关内容