Skip to content

Instantly share code, notes, and snippets.

@justincampbell
Created December 11, 2011 17:32
Show Gist options
  • Save justincampbell/1461697 to your computer and use it in GitHub Desktop.
Save justincampbell/1461697 to your computer and use it in GitHub Desktop.
Asterisk watchdog script
#!/bin/bash -x
DIR=/tmp/watchdog
# Create dir if it doesn't exist
if [ ! -d $DIR ]; then
mkdir $DIR
fi
cd $DIR
# Save current registration times
/usr/sbin/asterisk -rx "sip show registry" | grep "Registered" | cut -b 92- > current
# If last exists, compare current to last
if [ -f last ]; then
cmp current last
# If they match, restart Asterisk
if [ $? == 0 ]; then
/etc/init.d/asterisk restart
fi
fi
rm -f last
mv current last
# Add asterisk_watchdog.sh to cron
if ! grep -q "0,10,20,30,40,50 * * * * /etc/asterisk/asterisk_watchdog.sh" /var/spool/cron/root; then
echo "0,10,20,30,40,50 * * * * /etc/asterisk/asterisk_watchdog.sh">>/var/spool/cron/root
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment