#!/bin/sh # monitor_sip.sh # David Rowe 18 Feb 2010 # Adapted from script found on http://www.voip-info.org/wiki-IAX # # It was found that SIP # trunks we losing registration ever day or so as the ppp link IP # changed. The NAT router (Linux OpenWRT 2.4 box in my case) was mistakenly # sending SIP messages with the previous PPP IP, as it was # relying on some sort of internal hash table. Stopping SIP messages # for 2 minutes resets the NAT router. cd /usr/bin PATH=/sbin:/bin:/usr/sbin:/usr/bin while [ 1 ] do /sbin/asterisk "-rx sip show registry" 2>/dev/null > /tmp/sipshowregistry.txt sleep 1 # Test to see if our SIP trunk is up TEST="111720.*Registered" if grep $TEST /tmp/sipshowregistry.txt > /dev/null then echo "OK" sleep 60 # all is well... else echo "oops" # we have lost our SIP trunk, log problem and # restart Asterisk to get router NAT tables to reset date >> /var/log/monitor_sip.txt /etc/init.d/asterisk stop sleep 240 # & hopefully stops Asterisk disconnection when this script is killed /etc/init.d/asterisk start # give Asterisk time to wake up before we test start again sleep 60 fi done