List Info

Thread: How to access environment variable?




How to access environment variable?
country flaguser name
United States
2007-02-05 22:34:55
How can I access an environmental variable in Asterisk
1.2.5?

It should be possible according to:
http://www.voip-info.org/wiki/view/Asterisk+variables
which says:

Environment Variables
You may access unix environment variables using the syntax:
    ${ENV(foo)}
${ENV(ASTERISK_PROMPT)}: the current Asterisk CLI prompt.
${ENV(RECORDED_FILE)}: the filename of the last file saved
by the Record 
command


I have an environmental variable MYIP which contains my
current IP 
address but when I execute exten _4XX the following line
only says
'myip is  ' and the rest is blank instead of showing
'myip is   www.xxx.yyy.zzz'

exten => _4XX,n,VERBOSE("myip is 
${ENV(MYIP)}")

Why doesn't it work?

Larry


-- 
Larry Alkoff N2LA - Austin TX
Using Thunderbird on Linux
_______________________________________________
Austin-Asterisk-Users-Group mailing list
Austin-Asterisk-Users-Groupbybent.com
http://buzzard.onr.com/mailman/listinfo/austi
n-asterisk-users-group
AAUG Web Site: http://aaug.bybent.com/

Re: How to access environment variable?
user name
2007-02-05 23:52:19
On Mon, Feb 05, 2007 at 10:34:55PM -0600, Larry Alkoff
wrote:
> How can I access an environmental variable in Asterisk
1.2.5?
[...]
> I have an environmental variable MYIP which contains my
current IP 
> address but when I execute exten _4XX the following
line only says
> 'myip is  ' and the rest is blank instead of showing
> 'myip is   www.xxx.yyy.zzz'
> 
> exten => _4XX,n,VERBOSE("myip is 
${ENV(MYIP)}")
> 
> Why doesn't it work?

Did you export the environment variable?  If MYIP was not
exported
when you started Asterisk, then Asterisk won't see it. 
Additionally,
if you set an environment variable in the shell, for
example, and
then you connect to Asterisk in console mode (asterisk -r),
that
environment variable is not seen by the dialplan.

My money would be on the "not exported" problem
(see your shell's
man pages for details).

---
Gil Kloepfer
aaugkloepfer.org
_______________________________________________
Austin-Asterisk-Users-Group mailing list
Austin-Asterisk-Users-Groupbybent.com
http://buzzard.onr.com/mailman/listinfo/austi
n-asterisk-users-group
AAUG Web Site: http://aaug.bybent.com/

Re: How to access environment variable?
country flaguser name
United States
2007-02-06 07:53:17
Gil Kloepfer wrote:
> On Mon, Feb 05, 2007 at 10:34:55PM -0600, Larry Alkoff
wrote:
>> How can I access an environmental variable in
Asterisk 1.2.5?
> [...]
>> I have an environmental variable MYIP which
contains my current IP 
>> address but when I execute exten _4XX the following
line only says
>> 'myip is  ' and the rest is blank instead of
showing
>> 'myip is   www.xxx.yyy.zzz'
>>
>> exten => _4XX,n,VERBOSE("myip is 
${ENV(MYIP)}")
>>
>> Why doesn't it work?
> 
> Did you export the environment variable?  If MYIP was
not exported
> when you started Asterisk, then Asterisk won't see it. 
Additionally,
> if you set an environment variable in the shell, for
example, and
> then you connect to Asterisk in console mode (asterisk
-r), that
> environment variable is not seen by the dialplan.
> 
> My money would be on the "not exported"
problem (see your shell's
> man pages for details).
> 
> ---
> Gil Kloepfer
> aaugkloepfer.org
> 


Yes the MYIP variable is exported to bash.

It can be seen by the Asterisk CLI by
! echo $MYIP

It's not so important that the variable be seen by the
dialplan
but I want to use it in sip.conf to set externip.

Right now I use externhost=me.dyndns.org but the Asterisk
book says:
"externhost: Force Asterisk to perform DNS queries
periodically. 
                            Not recommended for production
environments! 
  Use externip instead."

OTOH, externhost seems to work.

Larry

-- 
Larry Alkoff N2LA - Austin TX
Using Thunderbird on Linux
_______________________________________________
Austin-Asterisk-Users-Group mailing list
Austin-Asterisk-Users-Groupbybent.com
http://buzzard.onr.com/mailman/listinfo/austi
n-asterisk-users-group
AAUG Web Site: http://aaug.bybent.com/

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )