我上周清理了我的 Apache 日志,现在开始出现这些错误。有什么办法可以解决这个问题吗?
/etc/cron.daily/logrotate:
logrotate_script: -c: line 1: syntax error near unexpected token `20'
logrotate_script: -c: line 1: ` find /var/log/apache2 -name "*.log.gz" -maxdepth 1 +mtime <20> -delete &>/dev/null'
error: error running shared postrotate script for '/var/log/apache2/*.log '
run-parts: /etc/cron.daily/logrotate exited with return code 1
文件:/etc/logrotate.d/apache2
/var/log/apache2/*.log {
daily
missingok
rotate 20
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
postrotate
find /var/log/apache2 -name "*.log.gz" -maxdepth 1 +mtime <20> -delete &>/dev/null
endscript
}
答案1
您应该检查一下您的 find 命令,尤其是这个,+mtime <20>
我不确定这是否是正确的语法。您是否将名为“20”的文件重定向到 find 命令中?
答案2
我不确定问题可能出在哪里,但可能是 2 个后旋转。尝试将两者合并在一起
/var/log/apache2/*.log {
daily
missingok
rotate 20
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
find /var/log/apache2 -name "*.log.gz" -maxdepth 1 +mtime 20 -delete &>/dev/null
endscript
}