#!/bin/bash # # Asterisk tool script by K0KN 4/2013. Last revised 3/09/2014 # # This script allows multiple functions to be carried out by a single # DTMF command in the Asterisk rpt.conf file, and also allows an # acknowledge audio file to be played to any node on the same # local Asterisk box. # # You can download the custom audio files via http or wget at: # www.qsl.net/k0kn/k0kn_extra_sounds.tgz # # Assign your DTMF commands to include your node number, target node number # (if other than your node), function and any arguments. # # Example: This command dials *72 on 2210 from node 2215. The # argument "1232210" on the end is included here only so that it appears # in the log file to indicate the DTMF that was dialed. # # 1232210=cmd,/home/kyle/asttool 2215 2210 star72 1232210 # # Example: This command activates auxillary pin 4 from node 2215. Since # auxillary 4 is defined in usbradio.conf under node 2211, this command # will operate the auxillary 4 switch but send the acknowledge message # to node 2215. # # 101=cmd,/home/kyle/asttool 2215 2211 pport 4 1 # # # Usage = asttool [node#] [target node#] [function] [argument1] [argument2] # SENDTO="TARGET EMAIL ADDRESS" SENDAS="SENDING EMAIL ADDRESS" SOUNDS="/etc/asterisk/sounds" MESSAGES="/var/log/asterisk/messages" LOGFILE="/var/log/asterisk/connectlog" TEMPFILE="/dev/shm/x.asttool.$1" if [ "$1" == "" -o "$2" == "" -o "$3" == "" ] ; then echo "Usage = asttool [node#] [target node#] [function] [argument1] [argument2]" ; exit fi # Assign GPIO/aux port status on/off by 1 or 0 if [ "$5" == 1 ] ; then ONOFF="on" fi # if [ "$5" == 0 ] ; then ONOFF="off" fi # # Assign aux 1,2,3,4 by parallel port pin number. # Parallel port 4 = aux1, 5 = aux2, 6 = aux3, 7 = aux4 if [ "$4" == 4 ] ; then AUX="1" fi # if [ "$4" == 5 ] ; then AUX="2" fi # if [ "$4" == 6 ] ; then AUX="3" fi # if [ "$4" == 7 ] ; then AUX="4" fi # Disable nodes if [ $3 == "disable" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/dtmf_received" echo $(date) "Asttool from $1 - Nightly disable script ran" >> $LOGFILE /home/kyle/disable fi # # Enable nodes if [ $3 == "enable" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/dtmf_received" echo $(date) "Asttool from $1 - Nightly enable script ran" >> $LOGFILE /home/kyle/enable fi # # Text messages disabled if [ $3 == "textoff" ] ; then touch /etc/asterisk/~statusdisable asterisk -rx "rpt localplay $1 $SOUNDS/textoff" fi # # Text messages enabled if [ $3 == "texton" ] ; then rm -f /etc/asterisk/~statusdisable asterisk -rx "rpt localplay $1 $SOUNDS/texton" fi # # Text connected nodes if [ $3 == "star72" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/textnodelist" /home/kyle/star72 $2 fi # # Send node stats if [ $3 == "stats" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/sending_node_stats" echo "Sending command: dailystats" /home/kyle/dailystats fi # # Enable parrot if [ $3 == "parrot_enabled" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/parrot_enabled" asterisk -rx "rpt cmd $2 cop 21 0" fi # # Disable parrot if [ $3 == "parrot_disabled" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/parrot_disabled" asterisk -rx "rpt cmd $2 cop 22 0" fi # # Enable chkconn if [ $3 == "en_chkconn" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/checkconnect_enabled" rm -f /etc/asterisk/~chkconn_disable fi # # Disable chkconn if [ $3 == "dis_chkconn" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/checkconnect_disabled" touch /etc/asterisk/~chkconn_disable fi # # DTMF command if [ $3 == "dtmf" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/dtmf_received" echo "Sending command: asterisk -rx rpt fun $2 *$4" asterisk -rx "rpt fun $2 *$4" fi # # Flip Nodes connections if [ $3 == "flip" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/dtmf_received" echo "Sending command: asterisk -rx rpt fun $2 *3$4" echo "Sending command: asterisk -rx rpt fun $1 *1$4" asterisk -rx "rpt fun $2 *3$4" asterisk -rx "rpt fun $1 *1$4" fi # # Pport command if [ $3 == "pport" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/aux$AUX$ONOFF" echo "Sending command: asterisk -rx rpt cmd $2 cop 62,PP$4=$5 0" asterisk -rx "rpt cmd $2 cop 62,PP$4=$5 0" fi # # GPIO command if [ $3 == "gpio" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/gpio$ONOFF" echo "Sending command: asterisk -rx rpt fun $2 *$4" asterisk -rx "rpt cmd $2 cop 62,GPIO$4=$5 0" fi # # Force unkey ptt if [ $3 == "unkey" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/ptt_unkeyed" echo "Sending command: asterisk -rx rpt cmd $2 cop 62,PP$4=0 0" asterisk -rx "rpt cmd $2 cop 62,PP$4=0 0" echo $(date) "Asttool from $1 to node $2 - force unkey ptt" >> $LOGFILE fi # # Nightdisable cancel if [ $3 == "nightdisable_cancel" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/disable_cancelled" echo "Sending command: touch /etc/asterisk/~disable" touch /etc/asterisk/~disable echo $(date) "Asttool from $1 - Nightly disable cancelled" >> $LOGFILE fi # # Nightdisable restore if [ $3 == "nightdisable_restore" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/disable_restored" echo "Sending command: rm -f /etc/asterisk/~disable" rm -f /etc/asterisk/~disable echo $(date) "Asttool from $1 - Nightly disable restored" >> $LOGFILE fi # # Severe WX disable if [ $3 == "severewx_disable" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/severe_wx_disabled" echo "Sending command: mv -f /home/kyle/severe_wx.ulaw /home/kyle/~severe_wx.ulaw" mv -f /home/kyle/severe_wx.ulaw /home/kyle/~severe_wx.ulaw echo $(date) "Asttool from $1 - Severe_wx audio file disabled " >> $LOGFILE fi # # Severe WX enable if [ $3 == "severewx_enable" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/severe_wx_enabled" echo "Sending command: mv -f /home/kyle/~severe_wx.ulaw /home/kyle/severe_wx.ulaw" mv -f /home/kyle/~severe_wx.ulaw /home/kyle/severe_wx.ulaw echo $(date) "Asttool from $1 - Severe_wx audio file enabled " >> $LOGFILE fi # # Email connectlog tail if [ $3 == "connectlog_tail" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/dtmf_received" SUBJECT="Asterisk Connectlog Tail" echo "Emailing connectlog tail" tail -n30 $LOGFILE > $TEMPFILE mail -s "$SUBJECT $(date)" $SENDTO -- -f $SENDAS < $TEMPFILE echo $(date) "Asttool from $1 - Email connectlog tail" >> $LOGFILE fi # # Email Asterisk messages tail if [ $3 == "messages_tail" ] ; then asterisk -rx "rpt localplay $1 $SOUNDS/dtmf_received" SUBJECT="Asterisk Messages Tail" echo "Emailing messages tail" tail -n30 $MESSAGES > $TEMPFILE mail -s "$SUBJECT $(date)" $SENDTO -- -f $SENDAS < $TEMPFILE echo $(date) "Asttool from $1 - Email messages tail" >> $LOGFILE fi # # done exit 0 fi