0

For a couple of months I didn't receive all the wanted log files by email upon the weekly log rotation and finally found the cause: two configs inside /etc/logrotate.d were broken, invalid. This on my Ubuntu 15.04 server.

That caused the logrotate service to crash in the middle.

I found that out myself by doing manual log rotations with

$ sudo logrotate -v -f /etc/logrotate.conf

I wish I were notified by email about that. Or to see some log entries about the failed logrotation in /var/log but no, nothing happened.

Do you have an idea how I can configure email alerts when logrotations failed themselves?? Or have these at least logged into something like /var/log/logrotation.log and /var/log/logrotation.err?

Thanks heaps

Michael Heuberger
  • 822
  • 3
  • 10
  • 27

1 Answers1

2

Setup a daily cron job to run logrotate using '-d'. If echo output is not zero then send an alert email using mailx or whatever you fancy. Sample:

#!/bin/sh

LOGROTATE_CONFPATH=/etc/logrotate.d

cd $LOGROTATE_CONFPATH
for i in `ls *`; do
  if ! logrotate -d $i &> /dev/null; then
      mail -s "ERROR IN LOGROTATE FILE:  $i" myemail@mycompany.com < /dev/null
  fi
done
Antonio López
  • 386
  • 6
  • 22