Linux

意外標記“20”附近的 logrotate 語法錯誤

  • March 7, 2015

我上周清除了我的 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
}

您應該查看您的 find 命令,特別是+mtime <20> 我不確定這是正確的語法。您是否將名為“20”的文件重定向到查找中?

我不確定問題可能出在哪裡,但可能與 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
}

引用自:https://serverfault.com/questions/673451