Hi Steve,
Yes, you can do that, and here’s a really, really short one I use to play pre-generated messages (mostly called from other scripts):
#!/bin/bash
mynode=`hostname | cut -c5-10`
asterisk -rx "rpt localplay $mynode $1"
In this case, mynode is a variable, and it parses my system’s hostname, which is node504389 and then cuts the last six characters to derive the node number. (I do this with all of my nodes and my scripts don’t require me to edit them for each particular node.)
You can do some pretty elaborate things including passing data into them…there are lots of great Linux utilities like cut
, sed
and awk
that end up doing my bidding.
This example I call copcmds.sh and it lets me use a generic command prefix:
#!/bin/bash
mynode=`hostname | cut -c5-10`
if [[ "$1" =~ ^[0] ]]
then
myvar=`echo $1 | cut -c2`
asterisk -rx "rpt cmd $mynode cop $myvar"
exit
elif [[ "$1" != ^[0] ]]
then
asterisk -rx "rpt cmd $mynode cop $1"
exit
fi
This is called from within rpt.conf as follows:
123=autopatchup,context=copcmds,noct=1,farenddisconnect=1,dialtime=60000,quiet=1
It then follows instructions inside of the extensions.conf to dynamically handle multiple digits:
[copcmds]
exten => _xx,1,System(/usr/local/sbin/copcmds.sh {$EXTEN})
exten => _xx,n,Hangup
This lets me execute any control operator command (“COP”) from the table, without having to write a specific command for each one. Commands with single digits are padded with a leading zero.
For example, if I want to turn on the time-out timer, I can enter *123 07
, which is the same as calling cop,7. Similarly, if I want to select an alternate hang timer, I can enter *123 19
, which would be the same as calling cop,19.
It’s important to note that this does not pass additional parameters on for COP commands which take extra parameters, such as POCSAG paging and the like…I didn’t want it to. You could change that by changing the dial pattern in extensions.conf to x.
, changing your cut
patterns, declaring a new variable to parse that, and so on. Don’t forget to chmod +x
your script when finished.
-John