Pass DTMF $1 to Called Shell Script

If in rpt.conf you add a line like …
700=cmd,/usr/local/do-it

The command runs after seeing *700. Anyone found a way to take the DTMF digits beyond the *700 and use them as parameter one ($1) in the do-it shell script?

That is … sending *7001234 … results in running …
/usr/local/do-it 1234

Any thoughts would be appreciated.
…STeve - KF5VH

Interesting question. I didn’t have time to look too deep but I did find this: https://community.asterisk.org/t/passing-asterisk-variables-to-python-script/75825

Is that helpful?

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

2 Likes