<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">&lt;<a href="mailto:trevor@tecnopolis.ca" target="_blank">trevor@tecnopolis.ca</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Seems simple.  What&#39;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 &#39;inet addr&#39; | awk &#39;{print \$2}&#39; | sed -e &#39;s/.*://&#39;`<br>
<br>
But the latest upgrade from F16 to F17 broke this (now the line contains<br>
&quot;inet&quot; but not &quot;inet addr&quot;.<br>
<br>
So I started thinking of finding the most standardized way that<br>
(hopefully) won&#39;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&#39;t guaranteed.<br>
<br>
Looks like ifconfig is now deprecated (according to man ifconfig).  So now<br>
I&#39;m doing:<br>
<br>
$eip=`ip -o -4 addr list eth0 | awk &#39;{print \$4}&#39;`<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&#39;t find any that have ip4 addr.  I<br>
tried to find more options to whittle ip&#39;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 &lt;<a href="mailto:sean@ertw.com" target="_blank">sean@ertw.com</a>&gt;    <a href="http://ertw.com/" target="_blank">http://ertw.com/</a>
</div>