我希望将logrotate配置为与写入/var/ log /apache2的所有其他日志文件分开处理/var/log/apache2/access.log。在不显式指定所有其他日志名称的情况下,有没有办法让它正常工作?
我在网上读到logrotate使用glob来匹配文件名,但我似乎写不出正确的模式。我尝试过许多模式,它们都有以下错误:
considering log /var/log/apache2/!(access.log)
log /var/log/apache2/!(access.log) does not exist -- skipping上面的模式在bash中是有效的,但只适用于shopt -s extglob。除了让apache将access.log写到自己的目录中,或者破坏非访问日志文件的名称之外,有没有一种方法可以用logrotate做到这一点?
我也尝试过使用prerotate脚本让它工作,但在尝试旋转access.log时失败了,但logrotate抱怨说我试图旋转access.log两次:
error: /etc/logrotate.d/apache2:16 duplicate log entry for /var/log/apache2/access.log这是我得到的最接近的:
# rotate access.log every time logrotate is called
/var/log/apache2/access.log {
missingok
rotate 168
compress
create 640 root adm
# rotate the log every time we call logrotate (size 0)
size 0
dateext
dateformat .%Y%m%d.%s
copytruncate
}
# rotate everything daily EXCEPT access.log
/var/log/apache2/*.log {
daily
missingok
rotate 7
compress
create 640 root adm
copytruncate
# filter out access.log, which we want to rotate on its own schedule above
nosharedscripts
prerotate
bash -c "[[ ! '$1' =~ /access.log ]]"
endscript
}发布于 2015-05-20 20:34:00
你是从cron运行的吗?您可以尝试使用bash -c "..“来执行cron脚本。以确保从bash调用logrotate。我不确定这是否有帮助。
https://stackoverflow.com/questions/23923916
复制相似问题