Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
    
I get error - awk: syntax error near line 1 awk: bailing out near line 1 –  yael Oct 18 '12 at 12:41
    
awk 'print $1,$8}' should be: awk 'print {$1,$8}' –  basvdlei Oct 18 '12 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 '12 at 13:23
    
Should be {print $1,$8} - fixed –  Iain Oct 18 '12 at 13:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.