Help with AGI File

Hi Guys can anyhelp with this?
I have this dialplan on my Asterisk

exten => _XXX,1,Answer()
same => n,SET(caller=${CALLERID(num)})
same => n,AGI(/home/sample/scripts/fname.sh)
same => n,NoOp(Got this ${fname})
same => n,SET(fname=${fname})
same => n,SET(CALLERID(name)=${fname})
same => n,Dial(SIP/${EXTEN})
same => n,Hangup()

In fname.sh file I have a MySQL Query lookup to get the callerid name of the caller using a variable I set in priority #2 of my dialplan same => n,SET(caller=${CALLERID(num)}). My question is how do I pass this variable on to my bash script so that it will be able to run the MySQL Query I created.

P.S. The MySQL query works, since I tested it at first by using a fixed value instead of a variable

TIA

Do you understand the difference between a shell script and an AGI?

If you are writing an ‘ordinary’ shell script, you may want to look at the SHELL function.

While you can write an AGI in sh, I’d advise against it. Most people use one of the ‘P’ languages and an AGI library written in that language. Personally, I’ve written most of my AGIs in C (using a library I wrote) because C is my sharpest tool.

The AGI protocol is not difficult, but it is easy to get wrong. You will save a lot of time using an established library. Nobody gets it right the first time.

You can push it onto the stack:
same => n,AGI(/home/sample/scripts/fname.sh,${caller})

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.