#!/bin/sh
# seconds between checks
WATCHDOG_SLEEP_SEC=20
# hostname or IP to ping

while sleep $WATCHDOG_SLEEP_SEC
do
if asterisk -rx "realtime mysql status" | grep connected > /tmp/null
then
echo "ASTERISK ok"
else
sleep 1
killall -9 asterisk
sleep 1
/etc/init.d/asterisk start
sleep 1
sendmail -v user@company.com < /etc/mail_alarm
fi
done 2>&1 & 
