#!/bin/bash # app_rpt toggle script by Kyle Yoksh, K0KN # October 2013. Last revised 10/8/2013 # # This script will allow you to set up a single command to toggle a # connection. For example: # # ast_toggle 2000 2210 - if these nodes are not connected, connect them # ast_toggle 2000 2210 - if these nodes are connected, disconnect them # # Usage = ast_toggle [your node#] [other node#] # FILENAME1="/dev/shm/toggle.tmp1" FILENAME2="/dev/shm/toggle.tmp2" LOGFILE="/var/log/asterisk/connectlog" if [ "$1" == "" -o "$2" == "" ] ; then echo "Usage = ast_toggle [your node#] [other node#]" ; exit fi asterisk -rx "rpt nodes $1" > $FILENAME1 cat $FILENAME1 | grep -v "*" > $FILENAME2 sed '/^$/d' $FILENAME2 > $FILENAME1 if grep -q "" $FILENAME1 ; then rm -f $FILENAME1 touch $FILENAME1 fi if grep -q "$2" $FILENAME1 ; then echo "$1 and $2 are connected -- disconnect" asterisk -rx "rpt fun $1 *1$2" echo $(date) "ast_toggle - $1 and $2 are connected -- disconnect" >> $LOGFILE else echo "$1 and $2 are not connected -- connect" asterisk -rx "rpt fun $1 *3$2" echo $(date) "ast_toggle - $1 and $2 are not connected -- connect" >> $LOGFILE fi # Clean up rm -f $FILENAME1 rm -f $FILENAME2 # Done! exit 0