I am using a trunk provider that has redundant servers but I can only be registered to one at a time. They suggested that I create a script to monitor the trunk and have it switch automatically but I am running into some issues getting FreePBX to cooperate.
So far this is what I have
#!/bin/bash
trunk=$(/usr/sbin/asterisk -x “pjsip show registrations” | sed -n 5p | awk ‘{print $2" "$3}’)
mysqlDL=$(mysql -u root asterisk -e “SELECT disabled FROM trunks WHERE name=‘ExampleDL’” | awk ‘{print $1}’ | sed -n ‘1!p’
mysqlNY=$(mysql -u root asterisk -e “SELECT disabled FROM trunks WHERE name=‘ExampleNY’” | awk ‘{print $1}’ | sed -n ‘1!p’
if [[ $trunk != “ExampleDL Registered” && $mysqlDL = “off” ]]; then
mysql -u root asterisk -e “UPDATE trunks SET disabled=‘off’ WHERE name=‘ExampleNY’”;
mysql -u root asterisk -e “UPDATE trunks SET disabled=‘on’ WHERE name=‘ExampleDL’”;
sed -i ‘s/ExampleDL/ExampleNY/g’ /etc/asterisk/pjsip.registration.conf
sed -i ‘s/server1.example.net/server2.example.net/g’ /etc/asterisk/pjsip.registration.conf
fwconsole reload
logger -s “ExampleDL Down On $(date)” 2>> /var/log/trunkstatus.log
fi
The mysql and sed commands work as intended and modify the database and config files. The changes are reflected in the FreePBX gui but when I get to ‘fwconsole reload’ the changes are reverted. Are there more spots that I need to modify to make these changes from the backend? Anybody have any other suggestions or ideas?
Any help is greatly appreciated as I have hit the brick wall.
Thanks.