Passing DTMF to Shell Scripts

Setting Up



So, somewhere in our dialplan, we need to create the context ‘pass2script’ and this is done in extentions.conf


[pass2script] ; this context needs to be unique in the system

exten = _X.,1,Wait,1

exten = _X.,n,SayAlpha(/var/lib/asterisk/sounds/activated,${EXTEN}) ; allison says something and then speaks the dtmf string {EXTEN}

exten = _X.,n,Wait,3 ; pause for a chance to cancel by hitting DTMF # (hangup)

exten = _X.,n,System(/source/of/ ${EXTEN}) ; here we pass the dtmf string to shell

exten = _X.,n,Hangup


So, *97 12345 in our example here, would pass 12345 to the shell for *97 is our executing command.

Outside of the ‘autopatch’ we used to capture and pass the dtmf, this dialplan is pure asterisk and you can use all asterisk dialplan functions for evaluating, reformatting and executing.

You will need your shell script to receive the ‘dtmf number string’ accordingly and help for that is available on the web as ‘passing variables to shell scripts’.

The skinny is that you would use the string inside your shell as “$1” since we have only one ‘argument string’ to pass for evaluation at a time.

You can evaluate and pass to internal asterisk/app_rpt functions as well, just using the dialplan.

Additionally evaluate that string inside your dialplan and send to different shell scripts.

Search www asterisk help for that. Inside the dialplan, the DTMF string is simply {EXTEN}

If you like to create your own functionality, you will find this tool/workaround essential for wide flexible control.

It has been well tested method since 2012, so if you are having any issues, check all your syntax.

You could have multiple autopatch dtmf hand-off’s as long as you first provide a new unique command number for it and a new unique context for it in your dialplan.

Practical uses can be site or home control via usb or network relays, radio control/ digital mode control functions, web execution scripts etc, all dependent on your script/dialplan.

So you can see that your imagination is your limit. Go for it.