Howto run a bash script with asterisk

Hi,

I’m trying to run a bash script via asterisk but it seems to me that asterisk just jumps over it…

following code is used in externsions_custom.conf

[custom-default]

exten => 100,2,System(/var/lib/asterisk/bin/post.sh ${data})

also tried:

exten => 100,2,TrySystem(/var/lib/asterisk/bin/post.sh ${data})

can someone please give me a hand…

Hi

Well heres one I have and that works OK

exten => h,1,system(/usr/local/sbin/hotdesk_in ${SIPCALLID} ${MY_EXTEN} ${CALLERIDNUM})

Are you sure the script runs OK. are all the commands correct. I always use lots of test calls and writing to files to test it works.

[quote=“ianplain”]Hi

Well heres one I have and that works OK

exten => h,1,system(/usr/local/sbin/hotdesk_in ${SIPCALLID} ${MY_EXTEN} ${CALLERIDNUM})

Are you sure the script runs OK. are all the commands correct. I always use lots of test calls and writing to files to test it works.[/quote]

thanks for the replay! :smile:

When i run the script in command it works great, but not in asterisk :frowning:

i just tried to run the following line:

[custom-default]

exten => 100,2,System(echo “${data}” >> /var/log/asterisk/myDebug.log)

and

exten => 100,2,System(touch /var/log/asterisk/myFile.test)

and both failed!! :open_mouth:

logfiles and full extension context/section you’re using. i just used your example on my Asterisk box and it worked. Asterisk running as user asterisk.

which logfile is of interest?

[custom-default] exten => 10000,1,Answer exten => 10000,2,DigitTimeout(7) exten => 10000,3,ResponseTimeout(10) exten => 10000,4,Flite("Welcome to XXX house heating") exten => 10000,5,Festival("At the beep enter the code to start or stop the heating system") exten => 10000,6,SIPDtmfMode(rfc2833) exten => 10000,7,Read(data,beep,10) exten => 10000,8,Flite("You entered the following code") exten => 10000,9,SayDigits("${data}") exten => 10000,10,Flite("Please hold a moment while sending command") exten => 10000,11,System(/var/lib/asterisk/agi-bin/post.sh ${data}) exten => 10000,12,Set(CALLERID(name)=${data}) exten => 10000,13,Dial(SIP/200,10) exten => 10000,14,Hangup

/var/log/asterisk/full for starters

this is what i get while running the script in the log

-- Executing TrySystem("SIP/100-088c88e0", "/var/lib/asterisk/agi-bin/post.sh "1234"") in new stack
    -- Executing Set("SIP/100-088c88e0", "CALLERID(name)=1234") in new stack
    -- Executing Dial("SIP/100-088c88e0", "SIP/200|10") in new stack
  == Everyone is busy/congested at this time (1:0/0/1)
    -- Executing Dial("SIP/100-088c88e0", "SIP/100|10") in new stack
    -- Called 100
    -- SIP/100-088d3d58 is ringing
  == Spawn extension (from-internal, 10000, 112) exited non-zero on 'SIP/100-088c88e0'
    -- Executing Macro("SIP/100-088c88e0", "hangupcall") in new stack
    -- Executing ResetCDR("SIP/100-088c88e0", "w") in new stack
    -- Executing NoCDR("SIP/100-088c88e0", "") in new stack
    -- Executing Wait("SIP/100-088c88e0", "5") in new stack
  == Spawn extension (macro-hangupcall, s, 3) exited non-zero on 'SIP/100-088c88e0' in macro 'hangupcall'
  == Spawn extension (macro-hangupcall, s, 3) exited non-zero on 'SIP/100-088c88e0'

i’m confused. your extension context says post.sh, but the log says post.agi. if it’s an AGI-compliant script, why not just use AGI to call it ?

asterisk works with root privilages ?
try chmod 777 post.sh (for test)
what post.sh do ?
can asterisk (privilages) do what is defined inside the script ?

it is not a AGI script, i just tried to change the file to *.agi to se if there would be a diffrens but there wasn’t one.

[quote=“fdragowski”]asterisk works with root privilages ?
try chmod 777 post.sh (for test)
what post.sh do ?
can asterisk (privilages) do what is defined inside the script ?[/quote]

post.sh runs a java program that in turn connects to a SocketServer…

#!/bin/bash

#exec the Java VM
/usr/java/jdk1.5.0_09/bin/java SocketClient $BASH_ARGV

did You try
exten => 100,2,System(/usr/java/jdk1.5.0_09/bin/java SocketClient ${data})
instead of running a bash script ?
any results ?

[quote=“fdragowski”]did You try
exten => 100,2,System(/usr/java/jdk1.5.0_09/bin/java SocketClient ${data})
instead of running a bash script ?
any results ?[/quote]

same problem…:cry:

Playing '/tmp/flite_buf_aaIjKI' (language 'en')
    -- Executing TrySystem("SIP/100-088da1e0", "/usr/java/jre1.5.0_07/bin/java SocketClient 1234") in new stack
    -- Executing Set("SIP/100-088da1e0", "CALLERID(name)=1234") in new stack
    -- Executing Dial("SIP/100-088da1e0", "SIP/200|10") in new stack
  == Everyone is busy/congested at this time (1:0/0/1)
    -- Executing Dial("SIP/100-088da1e0", "SIP/100|10") in new stack
    -- Called 100
    -- SIP/100-b7910dd0 is ringing

it looks like it’s runing but it never make the connection to my socket server…

btw, i am using trixbox 2.0 beta and i just found out that i can’t connect through WAN (I have set DMZ to Trixbox server) to register but i can ssh in to the server throug WAN…

maybe there is a connection problem? trixbox is blocking my java app?

tried with a new port 6080 - but still the same problem

and i also tried with AGI

-- Executing AGI("SIP/100-088e9198", "post.sh 1234") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/post.sh 1234 AGI Tx >> agi_request: post.sh 1234
AGI Tx >> agi_channel: SIP/100-088e9198
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1164630965.45
AGI Tx >> agi_callerid: 100
AGI Tx >> agi_calleridname: Cue
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 10000
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: from-internal
AGI Tx >> agi_extension: 10000
AGI Tx >> agi_priority: 9
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
    -- AGI Script post.sh 1234 completed, returning 0