[asterisk-users] how to pass a variable in extensions.conf to AGI file

Steve Edwards asterisk.org at sedwards.com
Sat Sep 13 15:09:59 CDT 2008


On Fri, 12 Sep 2008, Zen Kato wrote:

> I would like to pass global variable(i.e., ${CALLERID(num)}) in 
> extensions.conf to the variable in an AGI file 
> (/var/lib/asterisk/agi-bin/some-agi-file).

${CALLERID(num)} references a channel variable, not a global variable.

In the specific case of the channel variable you refer to, it is already 
"passed" to the AGI via stdin as part of the AGI setup.

In general, you don't "pass" variables to an AGI, the AGI "gets" the 
variable using the "get variable" AGI command. Try (in 1.2.x) "show agi" 
for more information.

> Can someone help me to implement the following?
>
> extensions.conf
> --------------
> exten => 9911,1,Answer
> exten => 9911,2,Wait(1)
> exten => 9911,3,Set(CALLER=${CALLERID(num)})
> exten => 9911,4,AGI(callall-9911-1)
> exten => 9911,5,AGI(callall-9911-2)
> exten => 9911,8,AGI(callall-9911-3)
>
> /var/lib/asterisk/agi-bin/callall-9911-1
> -----------------------------------------
> #!/bin/sh
> cp /var/lib/asterisk/agi-bin/demo1/call-all/telno/9911/* /var/tmp/call-all/9911
>
> /var/lib/asterisk/agi-bin/callall-9911-2
> -----------------------------------------
> #!/usr/bin/perl
> use strict;
> use Shell qw(rm);
> rm "/var/tmp/call-all/9911/".$CALLER;
>
> /var/lib/asterisk/agi-bin/callall-9911-3
> -----------------------------------------
> #!/bin/sh
> mv /var/tmp/call-all/9911/* /var/spool/asterisk/outgoing

Your "AGIs" do not read the AGI environment nor execute any AGI 
commands...

If all you want to do is copy, delete, and move files, the "system()" 
application would be more appropriate.

When you get to the point that you actually need the power of AGI, Perl 
would be a distant 3rd in my choice of implementation languages -- behind 
C and PHP.

The "agi debug" command will help resolve most AGI issues.

> There are 0103,0203,0303,0403,.,1003 files under /var/tmp/call-all/9911/.
>
> If I dial 9911 from username=0103, I would like to delete 0103 file,
> because 0103 is caller and callee.
>
> The perl script :
>
> rm  "/var/tmp/call-all/9911/".$CALLER;
>
> does not work.
>
>
> Regards,
>
> Zen

Unless your example above is contrived or "simplified," it indicates a 
need for a bit of reading. All that you show above could be accomplished 
with a couple of "system()" calls (each of which will create a new process 
-- considered an "expensive" operation) or as a single AGI (only creating 
a single new process).

Thanks in advance,
------------------------------------------------------------------------
Steve Edwards      sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                             Fax: +1-760-731-3000



More information about the asterisk-users mailing list