Dave Donovan wrote:
Bob,
The following AGI script will set an asterisk channel variable to your
current IP (eth0). The variable is destroyed at the end of the call.
If you want it longer than that, it's up to you to put it into the
database or a global variable.
#!/bin/bash
echo SET VARIABLE IPADDR \"$(ifconfig eth0 | awk '/inet addr/{print
$2}' | cut -d: -f2)\"
exit 0
The main line could be just:
echo SET VARIABLE IPADDR \"$(ifconfig eth0 | awk -F: '$1 = /inet addr/{print
$2}')\"
i.e., awk | cut is usually redundant.
And don't forget, this only works on a system with only one interface, and only
on
Linux where you don't get device-specific interface names (e.g, it will fail on
Solaris,
OpenBSD, NetBSD, FreeBSD, HP/UX, AIX and just about every other *NIX out there).
On at least OpenBSD you could change "eth0" to "egress" and have it probably
work (you'd
also remove the -F" and the " addr".
My real point is that relying on the output format of ifconfig is inherently
risky.
Ian