#!/bin/sh
LSOF=/usr/sbin/lsof
LOGGER=/usr/bin/logger
HOST='localhost'
PORT=110
#PORT=143
#HP=@$HOST:$PORT
HP=:$PORT
echo 'Checking to see if Dovecot is up...'
if ( $LSOF -Pni $HP | grep "$PORT (LISTEN)" 2>&1 >/dev/null ); then
echo 'Dovecot is up';
else
echo 'Dovecot is down, restarting...';
/etc/init.d/dovecot restart
$LOGGER -p mail.info dovecot_check_restart.sh restarting Dovecot
fi
* * * * * /etc/dovecot-check.sh 2>&1 > /dev/null