<div dir="ltr">my_public_ip=`curl <a href="http://ifconfig.me">http://ifconfig.me</a>`</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 23, 2013 at 10:40 PM, Trevor Cordes <span dir="ltr"><<a href="mailto:trevor@tecnopolis.ca" target="_blank">trevor@tecnopolis.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Seems simple. What's the best way (in a script) to get the IP address of<br>
an ethernet interface (in linux). For instance eth0.<br>
<br>
I used to have (perl, but also applies as a bash solution):<br>
<br>
$eip=`/sbin/ifconfig $int | grep 'inet addr' | awk '{print \$2}' | sed -e 's/.*://'`<br>
<br>
But the latest upgrade from F16 to F17 broke this (now the line contains<br>
"inet" but not "inet addr".<br>
<br>
So I started thinking of finding the most standardized way that<br>
(hopefully) won't change after a future kernel upgrade :-)<br>
<br>
It would seem that the less field parsing done, the better, as keywords<br>
and field position aren't guaranteed.<br>
<br>
Looks like ifconfig is now deprecated (according to man ifconfig). So now<br>
I'm doing:<br>
<br>
$eip=`ip -o -4 addr list eth0 | awk '{print \$4}'`<br>
<br>
That works now, but it still has a output format-dependent requirements.<br>
<br>
I looked for /sys or /dev files, but can't find any that have ip4 addr. I<br>
tried to find more options to whittle ip's output to give me just the<br>
address, no joy there.<br>
<br>
Ideas?<br>
<br>
PS: this is important as failures like this force me to drive out onsite<br>
to headless boxes, some of which are 200km away.<br>
_______________________________________________<br>
Roundtable mailing list<br>
<a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
<a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Sean Walberg <<a href="mailto:sean@ertw.com" target="_blank">sean@ertw.com</a>> <a href="http://ertw.com/" target="_blank">http://ertw.com/</a>
</div>