# Pass DTMF $1 to Called Shell Script

**URL:** <https://community.allstarlink.org/t/pass-dtmf-1-to-called-shell-script/15055>\
**Category:** AllStarLink\
**Created:** [June 2, 2019, 1:16pm UTC](https://community.allstarlink.org/t/pass-dtmf-1-to-called-shell-script/15055 "2019-06-02T13:16:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Mahler](https://community.allstarlink.org/user_avatar/community.allstarlink.org/steve_mahler/32/552_2.png) [@Steve\_Mahler](https://community.allstarlink.org/u/Steve_Mahler)\
**Post date:** [June 2, 2019, 1:16pm UTC](https://community.allstarlink.org/t/pass-dtmf-1-to-called-shell-script/15055/1 "2019-06-02T13:16:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![WD6AWP](https://community.allstarlink.org/user_avatar/community.allstarlink.org/wd6awp/32/5_2.png) [@WD6AWP](https://community.allstarlink.org/u/WD6AWP)\
**Post date:** [June 2, 2019, 2:23pm UTC](https://community.allstarlink.org/t/pass-dtmf-1-to-called-shell-script/15055/2 "2019-06-02T14:23:37Z")

</div>

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](https://community.asterisk.org/t/passing-asterisk-variables-to-python-script/75825)

Is that helpful?

---

<div class="post-metadata">

**Author:** ![AI3I](https://community.allstarlink.org/user_avatar/community.allstarlink.org/ai3i/32/2627_2.png) [@AI3I](https://community.allstarlink.org/u/AI3I)\
**Post date:** [January 21, 2020, 10:49pm UTC](https://community.allstarlink.org/t/pass-dtmf-1-to-called-shell-script/15055/3 "2020-01-21T22:49:54Z")

</div>

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
