I am new in asterisk and need help. I have a bash script that i need to run from my dial plan and get the value returned from it and put it into a variable in my dial plan.
For example my bash script is test.sh:
#! /bin/bash
echo "61"
My dial plan:
exten => 3333,1,Set(result=${shell(/root/test.sh)})
exten => 3333,2,Verbose(result is: ${result})
The script have a 777 Permissions and when I run it manually from the shell command line it is working. I want to run it from dialplan and use the returned value in a variable, I get nothing back ( no value returned )
My asterisk version is Asterisk 1.6.2.20
Your dialplan not work, becuase asterisk is running under asterisk user and can't read your script in root directory. To troubleshoot issues with script i recomend stop asterisk and start it in console as
asterisk -vvvgc
That way you will see errors generated by scripts.
BUT
Since there are no any difference in cpu cost between shell start and agi script start, i recomend you use AGI script.
To do it, you have put your script in /var/lib/asterisk/agi-bin/
#!/bin/bash
echo 'SET VARIABLE result "61" '
Dialplan will be
exten => 3333,1,AGI(test.sh)
exten => 3333,2,Verbose(result is: ${result})
p.s best practice is not use scripts at all, becuase starting shell is hi cpu cost operation and it will not scale well. Most of tasks can be done in dialplan, inluding complex checks and database query/update tasks.
Try to use ${SHELL(date)} to check if it works.
From my extensions.conf:
exten => 4002,1,Answer
exten => 4002,n,Set(RESULT=${SHELL(date)})
exten => 4002,n,NoOp(${RESULT})
exten => 4002,n,Hangup
From asterisk.log after call on 4002:
== Using SIP RTP CoS mark 5
-- Executing [4002@demo2:1] Answer("SIP/100-00000585", "") in new stack
-- Executing [4002@demo2:2] Set("SIP/100-00000585", "RESULT=Thu Jan 3 20:00:08 EET 2013
") in new stack
-- Executing [4002@demo2:3] NoOp("SIP/100-00000585", "Thu Jan 3 20:00:08 EET 2013
") in new stack
-- Executing [4002@demo2:4] Hangup("SIP/100-00000585", "") in new stack
== Spawn extension (demo2, 4002, 4) exited non-zero on 'SIP/100-00000585'*emphasized text*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With