how to show the servers IP address in a shell script ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • etech
    Confirmed User
    • Feb 2004
    • 1148

    #1

    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
  • SinSational
    Confirmed User
    • Oct 2004
    • 1723

    #2
    ifconfig -a

    ICQ# 273099174 - monthly specials - 2 Month Free Credit on All Plans - 100% Referrals - chris@ for details
    Virtual from $14.95/month, Dedicated from $149.95/month
    Dual-Core Xeon > 1000GB @ $149.95 | 1500GB @ $169.95 | 10Mbps @ $269.95

    Comment

    • etech
      Confirmed User
      • Feb 2004
      • 1148

      #3
      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 ?

      Comment

      • etech
        Confirmed User
        • Feb 2004
        • 1148

        #4
        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

        Comment

        • Brujah
          Beer Money Baron
          • Jan 2001
          • 22157

          #5
          backtick ?

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

          Comment

          • SteveF
            Confirmed User
            • Jan 2005
            • 120

            #6
            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.

            Comment

            Working...