Re: [Asterisk-Users] AGI script sample using bash shell script

2003-07-12 Thread Sunny Woo
[EMAIL PROTECTED],

During development of the bash script, I have problem reading the whole
string from the STDIN and I notice the next command won't get executed.

Notice the "case statements" that I have to implement to handle the read
line. This is because normally Asterisk will return one line "200 ...".
However, if the command is not properly written, like "SAY NUMBER"
instead of "SAY NUMBER 123 \"\" ", then Asterisk will return multiline
usage information back ... something like 

520-blah blah blah\n
blah blah blah blah\n
...
520 End of ...\n

The next command will not get executed until you read the last line.

Suggestions, play around with this:

echo "SAY NUMBER 123 \"\""   < Asterisk says 123
read line< Asterisk return 200
echo "SAY NUMBER 123"
read line< Asterisk return usage info.
   but we only read one line
echo "SAY NUMBER 345 \"\""   < this will not be executed
read line

Hope this helps,

Sunny Woo
Solutions Consultant
Avantnix


> Hey does that mean that whole perl script won execute or the next AGI command 
> wont execute. Cuz may be I get this problem too.
> ___
> Asterisk-Users mailing list
> [EMAIL PROTECTED]
> http://lists.digium.com/mailman/listinfo/asterisk-users


___
Asterisk-Users mailing list
[EMAIL PROTECTED]
http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [Asterisk-Users] AGI script sample using bash shell script

2003-07-12 Thread faizan
Quoting Sunny Woo <[EMAIL PROTECTED]>:

> 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. 
> 
Hey does that mean that whole perl script won execute or the next AGI command 
wont execute. Cuz may be I get this problem too.
___
Asterisk-Users mailing list
[EMAIL PROTECTED]
http://lists.digium.com/mailman/listinfo/asterisk-users


[Asterisk-Users] AGI script sample using bash shell script

2003-07-12 Thread Sunny Woo
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 <[EMAIL PROTECTED]>
#!/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