5

I get the following error when running a cron job, and I'm not too sure how to go about fixing. This is on Ubuntu 12.04 LTS.

test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

/etc/cron.daily/logrotate:
error: error running non-shared postrotate script for /var/log/fail2ban.log of '/var/log/fail2ban.log '
run-parts: /etc/cron.daily/logrotate exited with return code 1

Here is the contents of /etc/logrotate.d/fail2ban

/var/log/fail2ban.log {

    weekly
    rotate 4
    compress

    delaycompress
    missingok
    postrotate
    fail2ban-client set logtarget /var/log/fail2ban.log >/dev/null
    endscript

    # If fail2ban runs as non-root it still needs to have write access
    # to logfiles.
    # create 640 fail2ban adm
    create 640 root adm
}

Here is the /etc/cron.daily/logrotate file

#!/bin/sh

# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
    [ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
Errol Fitzgerald
  • 475
  • 1
  • 8
  • 17
  • change this line `fail2ban-client set logtarget /var/log/fail2ban.log >/dev/null` to `fail2ban-client set logtarget /var/log/fail2ban.log >/tmp/fail2banclient.out` and then run logrotate and tell us what gets put in `/tmp/fail2banclient.out` – user9517 May 19 '13 at 19:52
  • @lain I still seem to get the same error: error running non-shared postrotate script for /var/log/fail2ban.log of '/var/log/fail2ban.log ' – Errol Fitzgerald May 19 '13 at 20:13
  • 1
    @lain The contents of the /tmp/fail2banclient.out are ERROR Unable to contact server. Is it running? – Errol Fitzgerald May 19 '13 at 20:14

2 Answers2

9

ERROR Unable to contact server. Is it running?

Your fail2ban service isn't running start it!

service fail2ban start

or whatever starts it on your Ubuntu.

user9517
  • 115,471
  • 20
  • 215
  • 297
4

Add "notifempty" to /etc/logrotate.d/fail2ban. If fail2ban is installed but not running the log will be empty and will not be rotated.