0

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.

P Bear
  • 92
  • 1
  • 11
Sriram
  • 10,298
  • 21
  • 83
  • 136
  • You show the ownership, what about the permissions? Have you done `chmod ug+x main.sh` to make it executable? – Dennis Williamson Jan 29 '11 at 09:36
  • @Dennis: Yes, this script is executable with permissions 755. – Sriram Jan 29 '11 at 09:54
  • 2
    What happens when you run the command by hand, exactly as it was quoted in the error message? If Asterisk is saying it excited non-zero, that likely means there is an error occurring in your script. – payne Jan 29 '11 at 14:14
  • @payne: that was what the problem was. see my answer to the problem below. Is there a way to see what value a script returned when called from dialplan using System command? It might save me from making these mistakes in the future.. – Sriram Jan 31 '11 at 11:09
  • @Sriram, for the purpose use [SHELL function](http://www.itp-redial.com/class/weekly-notes/week4-notes/system-and-shell). It works just like System command, but returns script results. – Aleksey Saatchi Mar 28 '14 at 13:42

2 Answers2

0

I had the same problem and found another reason, which might be common: I had created the script on Windows, and copied over in binary mode. The text file contained the hidden ^M at each line end. I removed all of them and everything is fine! The error message is of course extremely misleading!

Klaus
  • 1
-1

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.

Sriram
  • 10,298
  • 21
  • 83
  • 136