0

I cleared out my apache logs last week and now started to get these errors. Any ideas how I can fix this?

/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

File: /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
}
John Magnolia
  • 1,723
  • 6
  • 28
  • 46
  • Bad syntax in /etc/logrotate/apache2? – Dan Mar 06 '15 at 09:47
  • I'm really not sure because none of the files in the errors have changed. I've added: etc/logrotate.d/apache2 – John Magnolia Mar 06 '15 at 16:36
  • Second postrotate section should not be there at all, is has bad syntax _and_ tries to delete old files itself, instead of letting logrotate do it's job – Dan Mar 06 '15 at 18:43

2 Answers2

2

You should review your find command, in particular this +mtime <20> I'm not sure that is proper syntax. Are you redirecting a file named '20' into the find?

toppledwagon
  • 4,245
  • 25
  • 15
1

I'm not sure where the issue might be but it might be with 2 postrotates. Try merging the two together

/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
}
Mike
  • 22,310
  • 7
  • 56
  • 79