Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

geting a bash returned value into asterisk dialplan

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

like image 833
user1946171 Avatar asked Jun 11 '26 23:06

user1946171


2 Answers

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.

like image 107
arheops Avatar answered Jun 15 '26 00:06

arheops


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*
like image 23
Igor Chubin Avatar answered Jun 15 '26 00:06

Igor Chubin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!