GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   how to show the servers IP address in a shell script ? (https://gfy.com/showthread.php?t=488979)

etech 07-06-2005 12:11 PM

how to show the servers IP address in a shell script ?
 
hostname -i just give me the adress on the lo interface, i need the ip address from the eth0 interface :helpme

SinSational 07-06-2005 12:14 PM

ifconfig -a

etech 07-06-2005 12:18 PM

Quote:

Originally Posted by SinSational
ifconfig -a

Yes, but that show all the info, i just need the IP.
I could do a grep, but aint there any commands getting the IP address ?

etech 07-06-2005 12:28 PM

I got it, ifconfig eth0 |grep 'inet addr' |awk '{print $2}'
My main problem now is that I need to get that saved in a variable, and i cant do
VAR = ifconfig eth0 |grep 'inet addr' |awk '{print $2}'
echo $VAR

Brujah 07-06-2005 12:53 PM

backtick ?

get the ip from /etc/sysconfig/network-scripts/ifcfg-eth0 ?

SteveF 07-06-2005 02:21 PM

This example works in a bash environment, just surround your command line in such a fashion:

[sf@steve]$ export TEST=`ifconfig rl0|grep netmask|awk '{print $2}'`
-=[~]=- -=[Wed Jul 06]=- -=[17:18:06]=-
[sf@steve]$ echo $TEST
xxx.xxx.xxx.xxx (replaced for obvious reasons)

You'll have to narrow the search down more if you have virtual IPs bound to the same interface, etc.

S.


All times are GMT -7. The time now is 03:30 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123