1

how to find the device name as ( e1000g2 , e1000g3 , etc ) according to his IP address on Solaris machine

for example

   ifconfig -a | grep 10.106.134.133

       inet 10.106.134.133 netmask ffffff00 broadcast 10.106.134.255

ifconfig with grep command view only the line with the IP address , and the device name appears before the IP address

so my target is to match the device name according to the IP address on Solaris machine , and then insert the device name in to parameter ( ksh )

please advice?

full example: from ifconfig -a ( I get the IP and device name , what I need is to find the device name according to IP address , and insert the device name in to parameter )

 e1000g2: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500            inet 10.106.134.133 netmask ffffff00 broadcast 10.106.134.255

1 Answer 1

1

This feels like a horrible hack but for now

#!/bin/ksh
ipaddr=$1
ifconfig -a | nawk '/'"$ipaddr"'/ { printf "%s",prev;print };{prev=$0}' | awk '{print $1,$8}'

and

usage scriptname ip.add.re.ss
4
  • I get error - awk: syntax error near line 1 awk: bailing out near line 1
    – yael
    Oct 18, 2012 at 12:41
  • awk 'print $1,$8}' should be: awk 'print {$1,$8}'
    – basvdlei
    Oct 18, 2012 at 13:02
  • ifconfig -a | nawk '/'"$ipaddr"'/ { printf "%s",prev;print };{prev=$0}' | awk 'print {$1,$8}' awk: syntax error near line 1 awk: bailing out near line 1
    – yael
    Oct 18, 2012 at 13:23
  • Should be {print $1,$8} - fixed
    – user9517
    Oct 18, 2012 at 13:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .