[Asterisk-Users] AGI script sample using bash shell script
Sunny Woo
sunnywoo at yahoo.com
Sat Jul 12 13:42:35 MST 2003
Hi,
A quick and dirty (aka Rapid Application Developement) AGI script
implement using bash shell. No need to invoke a 10MB perl engine to
process simple asterisk agi scripts.
I found it to be very useful in learning the AGI interface. For example,
I learn that AGI won't execute the next command until you read the
results from STDIN.
Enjoy,
Sunny Woo
Solution Consultant
Avantnix
=========================== agi-test-bash.agi ======================
#!/bin/bash
declare -a array
while read -e ARG && [ "$ARG" ] ; do
array=(` echo $ARG | sed -e 's/://'`)
export ${array[0]}=${array[1]}
done
# following variables are available from asterisk
echo $agi_request >&2
echo $agi_channel >&2
echo $agi_language >&2
echo $agi_type >&2
echo $agi_uniqueid >&2
echo $agi_callerid >&2
echo $agi_dnid >&2
echo $agi_rdnis >&2
echo $agi_context >&2
echo $agi_extension >&2
echo $agi_priority >&2
echo $agi_enhanced >&2
checkresults() {
while read line
do
case ${line:0:4} in
"200 " ) echo $line >&2
return;;
"510 " ) echo $line >&2
return;;
"520 " ) echo $line >&2
return;;
* ) echo $line >&2;; #keep on reading those Invlid command
#command syntax until "520 End ..."
esac
done
}
echo "1. Testing 'sendfile' ..." >&2
echo "STREAM FILE beep \"\""
checkresults
echo "2. Testing 'sendtext' ..." >&2
echo "SEND TEXT \"hello world\""
checkresults
echo "3. Testing 'sendmage' ..." >&2
echo "SEND IMAGE asterisk-image"
checkresults
echo "4. Testing 'saynumber' ..." >&2
echo "SAY NUMBER 192837465 \"\""
checkresults
echo "5. Testing 'waitdtmf' ..." >&2
echo "WAIT FOR DIGIT 1000"
checkresults
echo "6. Testing 'record' ..." >&2
echo "RECORD FILE testagi gsm 1234 3000"
checkresults
echo "6a. Testing 'record' playback" >&2
echo "STREAM FILE testagi \"\" "
checkresults
echo "=================== Complete ====================" >&2
=========================== agi-test-bash.agi ======================
--
Sunny Woo <sunnywoo at yahoo.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: agi-test-bash.agi
Type: text/x-sh
Size: 1429 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20030712/fbaa3c8e/agi-test-bash.sh
More information about the asterisk-users
mailing list