Using custom dialplan to run script


I would suggest as a diagnosis running the script verbosely as the user that will be running it , capturing any errors and then browsing the output line by line

su asterisk -c "python -v  /var/lib/asterisk/bin/ 2>&1 |less"

(Stuart Murtland) #22

Right we are working again from asterisk user console - for some reason -maybe a reboot - the permissions for /dev/gpiomem had reverted back to asterisk user not having file permissions and the GPIO setting are refered to in the script. However if from the console i just run “/var/lib/asterisk/bin/” - it does not run - reporting import commands not found, but if i run it with python in front i.e. “python /var/lib/asterisk/bin/” it does run.
Should i have python in front here?:

[unlock-gate] exten => s,1,NoOp(Entering user defined context unlock-gate in extensions_custom.conf) exten => s,n,TrySystem(python /var/lib/asterisk/bin/ exten => s,n,NoOp(Script status: ${SYSTEMSTATUS}) exten => s,n,Hangup
Or am i chasing a red herring?


Post your script, it is all about the ‘environment’ so the #! line (line 1) is often better as #!/usr/bin/env python2 but depending on how you wrote it maybe #!/usr/bin/env python3

(Stuart Murtland) #24

import RPi.GPIO as GPIO
import time



except KeyboardInterrupt:


yes, you either need a #! line to set which python to run as, or just call it through python as you discovered.

For gpio permissions, add udev rules as appropriate

(Stuart Murtland) #26

Hi dicko
Thank you for all your time - i don’t really understand what “For gpio permissions, add udev rules as appropriate” means but i will google it.
So i can modify the line " exten => s,n,TrySystem(python /var/lib/asterisk/bin/" as so?


I would add a full path to the version of python you want to run the script as, either as a hashbang in the script or in the trysystem call.

(Yep, google is your friend, udev rules run on boot and are used in this case to expose the gpio pins cleanly to users not in the gpio group)

(Stuart Murtland) #28

Thanks a lot - got to leave it for today.

(Stuart Murtland) #29

Hi All
i am now back at my desk and on it again. Thanks to Lorne and a big thanks to dicko, this is now working a treat (still to get my head round and sort the undev rules, but that should be today). In the end i modified the line to start with python - " exten => s,n,TrySystem(python /var/lib/asterisk/bin/"
Big thanks to everyone that contributed. Cheers