hello, all of users:
this is a simple script to let the system check the status of asterisk. if it stopped or died, the sysem would automatically send an email to you. if you know more about asterisk, you can let the asterisk call you when the asterisk restart. of course,
you can add other info of zaptel, mISDN in the script. you also can adjust the tme according to your system condition.
==========================================================================================================
#!/bin/bash
# Add the following line to your crontab
#*/5 * * * * root /root/bin/asterisk-watchdog
LOCKFILE=/tmp/asterisk-watchdog-disable
SOCKETFILE=/var/run/asterisk.ctl // access socket
PIDFILE=/var/run/asterisk.pid // check the PID
[email protected] // send email to admin.
if [ "$1" = "test" ]; then
MESSAGE="asterisk-watchdog notification: test notification on `hostname` at `date`"
else
[ -f $LOCKFILE ] && exit 0 # check to see if watchdog is temporarily disabled
[ -S $SOCKETFILE -a -f $PIDFILE ] && exit 0 # check for existence of asterisk ctl socket
/etc/init.d/asterisk start # restart asterisk if the socket is not there
sleep 5 # give asterisk some time to stabilize of die
if [ -S $SOCKETFILE ]; then # check again, notify if its up or down
MESSAGE="asterisk-watchdog notification: asterisk restarted on `hostname` at `date`"
else
MESSAGE="asterisk-watchdog notification: asterisk is down and not recovered on `hostname` at `date`"
fi
fi
echo "Sending the following message to $ADMINEMAIL:"
echo "$MESSAGE"
echo "$MESSAGE" | mail $ADMINEMAIL -s "$MESSAGE" // send email.
==============================================
regards!
James.zhu