Script to reboot in case of too many MailScanner crashes

Denis Beauchemin Denis.Beauchemin at usherbrooke.ca
Fri Aug 26 18:53:31 UTC 2016


Hello,

Some time ago I wrote this script to reboot one server if there were more than 3 MailScanner crashes since the last reboot. I did this because I had MailScanner flag all emails as causing a crash. Rebooting the server solved the problem (but not restarting the service). I run this script in root’s crontab every 5 minutes:

NB_ERRS=$(egrep "it has been attempted too many times|clamd daemon|clamd.*: Self checking every 600 seconds|aliases rebuilt by root|dccifd for ASCII protocol" /var/log/maillog|awk 'BEGIN{nb=0}/Warning: skipping message/{nb++;next}{nb=0;next}END{print nb}')

#!/bin/bash
if [[ "$NB_ERRS" -gt 3 ]]; then
        echo "Rebooting $(hostname -s): $NB_ERRS errors found since last reboot!"
        /sbin/reboot
else
        echo "OK: $NB_ERRS errors found since last reboot"
fi

The script will reset its count of MS crashes if it finds the server rebooted after the crashes.

It worked fine on my RHEL 6 servers.

Denis

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mailscanner.info/pipermail/mailscanner/attachments/20160826/9614600c/attachment.html>


More information about the MailScanner mailing list