Thanks for the caveats Ian. I thought of that when I put in the ETH0 but I forgot to mention it when I posted. I was kinda sleepy.
I forgot to put the warning banner: Caution - Ugly Hack I wasn't happy using ifconfig but when I went around looking for a command that just spit back an IP address, I realized that it's not really as simple as one might think. Which IP address? Which interface? For instance, I resolved hostname but all I got back was 127.0.0.1. That's not very helpful. I did find an interesting application of the diaplan app CURL somewhere (maybe in the Wiki) that uses http://checkip.dyndns.org to return your external IP as the world sees you. It was actually easier, and it seems maybe more reliable than trying to return the address of a local interface. I wasn't able to run either of your suggested commands successfully. I'm not sure why. Here's where I confess that I borrowed that awk syntax from someplace not really knowing _why_ it worked. But still, the command you posted returns: 192.168.xxx.yyy Bcast and if I remove the -F and 'addr' I get: addr:192.168.xxx.yyy In any case, mine definitely isn't an elegant solution. As you say, Bob would be well advised to find something more reliable. Thanks again for your constructive input, Dave On 1/17/06, Ian Darwin <[EMAIL PROTECTED]> wrote: > 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 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- David Donovan Consultant Fulcrum Solutions
