返回列表 發帖

QNAP Asterisk SIP IP Tracking

trunk_ip_check.sh
  1. #!/bin/sh
  2. PEER="sz-gw"
  3. ASTCMD="/opt/sbin/asterisk -rx"
  4. NSLCMD="ping -c 1"

  5. OLD_IP=`$ASTCMD "sip show peer $PEER" | grep "Addr->IP" | cut -c 16- | cut -f2 -d\ `

  6. PEER_HOST=`$ASTCMD "sip show peer $PEER" | grep "ToHost" | cut -c 16- | cut -f2 -d\ `

  7. NEW_IP=`$NSLCMD $PEER_HOST | head -1 | cut -f3 -d\ | sed s/:// | sed s/\(// | sed s/\)//`

  8. if [ $NEW_IP != $OLD_IP ]
  9.       then
  10.         $ASTCMD "sip reload"
  11.         echo "$PEER `date` IP changed from $OLD_IP to $NEW_IP then sip reload" >> /opt/etc/asterisk/trunk_ip_change.dat
  12. fi
複製代碼
In the file /mnt/HDA_ROOT/.config/crontab add the following cron job
  1. */5 * * * * /bin/sh /opt/etc/asterisk/trunk_ip_check.sh
複製代碼
Restart the cron routine
  1. /etc/init.d/crond.sh restart
複製代碼
YH

返回列表