Search code examples
bashscriptingasterisktelephony

Bash script in agi-bin fails to execute - asterisk


I am trying to execute a bash script from within my dialplan. The bash scripts are from within a directory projectFiles in /var/lib/asterisk/agi-bin. When I try to execute the script, like so:

exten => 0,n,System(/var/lib/asterisk/agi-bin/projectFiles/main.sh ${RECORDED_FILE}.wav ${SOUND_PATH}/menus/wav2.wav)  

I end up with the following error:

WARNING[27515]: app_system.c:125 system_exec_helper: Unable to execute '/var/lib/asterisk/agi-bin/projectFiles/main.sh /tmp/rec62.wav /var/lib/asterisk/sounds/en/projects/menus/wav2.wav'
  == Spawn extension (test-project, 0, 5) exited non-zero on 'DAHDI/15-1'   

The permissions to the script main.sh are set at asterisk as owner and group. Where might I be going wrong?

Any help is most welcome,
Sriram.


Solution

  • The script within agi-bin, main.sh did not execute successfully. Hence the error message. One line within main.sh copied $1 of the input arguments to the present working directory, which I had assumed would be the same directory in which the script was placed. $HOME for asterisk (and from where it executes all scripts) is /etc. So, a line like the following:

    cp $1 .
    

    would copy $1 to /etc. This caused mayhem further down the script. Changing that line makes everything work OK.