How to Execute a Bash Script from Asterisk's extensions.conf?

I am working on an Asterisk configuration, and I want to execute a Bash script from within the extensions.conf file. The script is intended to perform certain actions based on call events. Can someone provide guidance on how to achieve this? Specifically:

  1. What is the correct syntax for calling a Bash script within the extensions.conf file?
  2. Are there any considerations or best practices for running Bash scripts in this context?
  3. How can I pass parameters or variables from Asterisk dialplan to the Bash script?

Any insights, examples, or recommendations would be greatly appreciated!

I have tried these,
exten => 123,1,Answer()
exten => 123,2,System(/path/to/
; or
exten => 123,3,AGI(/path/to/

Yes you can. here is an example that I have in production and has been solidly executed a couple thousand times.

exten => _123XXXX,n,AGI(,${number},${digits},${CALLERID(num)} )

I am also sending through variables to the script as well.

1 Like

Sorry @Vignesh-AK , I did not complete my answer.
So what I gave you executes a simple python script and is basic. There are a number Asterisk documents that you should read and there are quite a few posts about running scripts in the dial plan that you can follow, for example:

Also I found reading the Chapter called “Asterisk Gateway Interface (AGI)” from the book Asterisk Definitive Guide helped with some of the basics.

Another good resource is Asterisk cmd AGI - VoIP-Info
It contains links for uses of AGI

In my Example I am not using a Bash script however, it does show sending variables that will get used with the script.

Did you already try running a script?

I find that even making a simple script that writes your variables to a file will give you some experience and you can see what happens without breaking anything, of course on a test system :wink:

1 Like

If this means things like read a keystroke, play a file, lookup something from a database, this may imply something beyond a ‘Bash script’ (executed by system()) that would be more appropriate as an AGI (executed by agi()).

You can write an AGI in Bash, but IMO, it is not worth the pain.

You should write an AGI in any language you are comfortable and has an established AGI library. Meaning any of the ‘P’ languages, C, Go, Rust, etc. Compiled languages are more performant, but it usually doesn’t matter until you’re processing lots of calls.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.