How to echo bash script operation back to Asterisk console?

Hi Folks,
I’m pretty much a noob at Asterisk but have come a long way.
I’m running a bash script form the dialplan successfully but I’m seeing no real feedback from it in my Asterisk console.

; MySQL Test Extension
exten => 800,1,Answer()
same => n,Set(CLI=${CALLERID(num)})
same => n,Verbose(CLI is ${CLI})
same => n,Set(CODE=${ODBC_TEST(${CLI})})
same => n,Verbose(Returned code is ${CODE})
same => n,SayNumber(${CODE})
[color=#FF0040]same => n,AGI(${scripts}[/color]
same => n,Hangup()

So above is where I’m calling the script, and below is the script itself (very simple).


if echo “” | nc 63333; then
echo "Server Alive!!"
echo "Oops Server Dead"

What I’m trying to do is see if the machine at the IP address is up and get that feedback in the Asterisk console much like the “Verbose” application. The only feedback I see is :-

-- Launched AGI Script /home/scripts/
-- <SIP/1000-00000001>AGI Script /home/scripts/ completed, returning 0

I’d like to see either “server alive” or “Oops server dead” message in Asterisk console.

Can’t find anything on the tinterwebz so I’m leaning towards myself missing something very important like it can’t be done?!

I’m just doing this as part of my learning so I’d be very grateful for some advice on what I’m missing and which direction I should be going…

Thanks in advance :smile:

you should put the output in a variable and then user NoOP() application in your dialplan to see the output . you can use arguments to pass user defined variables to your agi script and see the result by NoOP() app . Maybe its better to play a file in each situation .

Hi thanks for your reply,
How do I put the output into a variable please using my code as an example?

I’ve only just started to learn basic shell scripts so at the moment im struggling :frowning:

I dont use shell script to write agi scripts . Im using PHP and the PHPAGI library an I suggest you to pick one of the PHP , Pyhton , Perl or other scripting language to write such applications as you can find libraries that makes thing more simple . for example for showing input variable in console from input the script will be as follow in php using phpagi library .

#!/usr/bin/php -q

<?php set_time_limit(30); require('phpagi.php'); $agi = new AGI(); $input_variable = $argv[1]; $agi->verbose(“input variable is $input_variable”); $agi->hangup() ?>