0

I am struggling with this problem. In Asterisk, I need to execute an external script after leaving a voicemail message. For this, I enabled externnotify in voicemail.conf but it was not working. So I searched in C code and found the related code. The command that executes the external script is:

execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);

in which s is /usr/bin/myscript.sh default 2000 12 8 0 &. excel runs in child process successfully but the script myscript.sh which is:

#!/bin/sh
CONTEXT=$1
EXTEN=$2
NUMVMS=$3
echo "$CONTEXT $EXTEN $NUMVMS" > /home/testfile 

is not executed. The strange part is I wrote another C file and put the execl command in it and it executes my script successfully. I replaced execl with system command but no success again. Which part have I done wrong?

Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105
AmirA
  • 133
  • 2
  • 15

1 Answers1

0

First of all i have say you, that voicemail ALREADY have notify functionality and it works ok.

About why your script not work - likly you tested it under root user, while most asterisk running under asterisk user, so you have permission issue on write to your log file.

arheops
  • 15,544
  • 1
  • 21
  • 27
  • First of all, thank you for your answer. Actually I changed the owner and group of my script to asterisk. isn't it ok? what should I do? – AmirA Jan 25 '18 at 16:11
  • you should temporary enable login for asterisk user, login as asterisk, run script,see error. after that ensure you asterisk user have nologin. – arheops Jan 25 '18 at 20:21
  • I did what you said, but I didn't see any error. where I should see errors? in the asterisk log file? no error happens in there. – AmirA Jan 26 '18 at 06:57
  • You should debug script using commandline using asterisk user and see error. If you unsure how asterisk call it, you can use asterisk debug(core set debug 5) – arheops Jan 26 '18 at 10:46
  • I have already done all of these suggestions and then posted my question here. I even added some code for debugging purpose inside C file `asterisk.c` which is responsible for this matter. In logger.conf I enabled full log. As I said before, `execl` runs successfully and produces no errors in log file but doesn't execute the script. – AmirA Jan 26 '18 at 11:30