shell代码:

  1. #!/bin/bash 
  2. Add the following line to your crontab 
  3. #*/5 * * * *     root    /root/bin/asterisk-watchdog 
  4.  
  5. LOCKFILE=/tmp/asterisk-watchdog-disable 
  6.  
  7. SOCKETFILE=/var/run/asterisk.ctl 
  8. PIDFILE=/var/run/asterisk.pid 
  9.  
  10. ADMINEMAIL=admin@bogus.mail 
  11.  
  12. if [ "$1" = "test" ]; then 
  13.     MESSAGE="asterisk-watchdog notification: test notification on `hostname` at `date`" 
  14. else 
  15.     [ -f $LOCKFILE ] && exit 0  # check to see if watchdog is temporarily disabled 
  16.     [ -S $SOCKETFILE -a -f $PIDFILE ] && exit 0 # check for existence of asterisk ctl socket 
  17.  
  18.     /etc/init.d/asterisk start  # restart asterisk if the socket is not there 
  19.  
  20.     sleep 5             # give asterisk some time to stabilize of die 
  21.  
  22.     if [ -S $SOCKETFILE ]; then # check again, notify if its up or down 
  23.             MESSAGE="asterisk-watchdog notification: asterisk restarted on `hostname` at `date`" 
  24.     else 
  25.             MESSAGE="asterisk-watchdog notification: asterisk is down and not recovered on `hostname` at `date`" 
  26.     fi 
  27. fi 
  28.  
  29. echo "Sending the following message to $ADMINEMAIL:" 
  30. echo "$MESSAGE" 
  31.  
  32. echo "$MESSAGE" | mail $ADMINEMAIL -s "$MESSAGE" 

安装脚本:

  1. #!/bin/bash 
  2.  
  3. mkdir /root/bin/ 
  4. cd /root/bin 
  5.  
  6. if [ -f asterisk-watchdog ]; then 
  7.         echo "/root/bin/asterisk-watchdog already exists" 
  8.         exit 1 
  9. fi 
  10.  
  11. wget http://www.bluecrow.net/files/asterisk/asterisk-watchdog/asterisk-watchdog http://www.bluecrow.net/files/asterisk/asterisk-watchdog/asterisk-watchdog-crontab http://www.bluecrow.net/files/asterisk/asterisk-watchdog/asterisk-watchdog-disable http://www.bluecrow.net/files/asterisk/asterisk-watchdog/asterisk-watchdog-enable 
  12.  
  13. cat asterisk-watchdog-crontab >> /etc/crontab 
  14. rm -f asterisk-watchdog-crontab 
  15. /etc/init.d/crond reload 
  16.  
  17. chmod 755 asterisk-watchdog* 
  18. ./asterisk-watchdog-enable 
  19.  
  20. echo "asterisk-watchdog has been installed into crond and enabled" 

资源链接 http://files.bluecrow.net/asterisk/asterisk-watchdog/