Grabbing IP and zonename from multiline 'ifconfig' output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grabbing IP and zonename from multiline 'ifconfig' output
# 1  
Old 10-30-2012
Grabbing IP and zonename from multiline 'ifconfig' output

Hi There,

I have a Solaris server that has a bunch of zones configured and I am trying to write a script that will take all interfaces other than the loopback ones (e.g. lo0:3 etc) and present them so that I can easily determine the zone that owns the IP

So in the case of the following ifconfg output



Code:
# ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000
lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone myzone1
        inet 127.0.0.1 netmask ff000000
lo0:2: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone myzone2
        inet 127.0.0.1 netmask ff000000
lo0:3: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone myzone3
        inet 127.0.0.1 netmask ff000000
lo0:4: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone myzone4
        inet 127.0.0.1 netmask ff000000	
nxge3: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        inet 10.90.24.145 netmask ffffff00 broadcast 10.90.24.255
        groupname MAIN
        ether 0:21:28:e5:xx:xx
nxge3:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        inet 0.0.0.0 netmask ff000000 broadcast 0.255.255.255
nxge3:2: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        zone myzone1
        inet 10.90.24.82 netmask ffffff00 broadcast 10.90.24.255
nxge3:3: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        zone myzone2
        inet 10.90.24.81 netmask ffffff00 broadcast 10.90.24.255
nxge3:4: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        zone myzone3
        inet 10.90.24.83 netmask ffffff00 broadcast 10.90.24.255
nxge3:5: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        zone myzone4
        inet 10.90.24.84 netmask ffffff00 broadcast 10.90.24.255

I would get something like

Code:
iface		ip			zonename
nxge3		10.90.24.145	
nxge3:1		0.0.0.0			
nxge3:2		10.90.24.82		myzone1
nxge3:3		10.90.24.81		myzone2
nxge3:4		10.90.24.83		myzone3
nxge3:5		10.90.24.84		myzone4


Im a little unsure how I would get it to treat each individual block of ifconfig output as a seperate entity as clearly the virtual IP's for the zones are laid out differently by ifconfig than the non zone/main IP's (eg. nxge3) .. youll notice that the ip address line is positioned differently.

I have to capture all valid IPs in the report whether they are linked to a zone or not ..

Any advice or guidance on what would be a good starting point for me would be greatly appreciated, as im not really sure how to tackle this one

Regards
# 2  
Old 10-30-2012
Try piping the output to the below code:-

Code:
awk 'BEGIN { print "iface ip zonename"; } /^nxge/,/[.*]$/ {
        if(match($1,/nxge/)>0)
                printf("\n%s",$1);
        if(match($1,/inet/)>0)
                printf(" %s",$2);
        if(match($1,/zone/)>0)
                printf(" %s",$2);
} '

This User Gave Thanks to Yoda For This Post:
# 3  
Old 10-31-2012
thats brilliant, thanks for that

the output appears as


Code:
iface ip zonename

nxge3: 10.90.24.145
nxge3:1: 0.0.0.0
nxge3:2: myzone1 10.90.24.82
nxge3:3: myzone2 10.90.24.81
nxge3:4: myzone3 10.90.24.83
nxge3:5: myzone4 10.90.24.84



Ive been having a play around with it as id really like the IP address to appear in the second column as per the headings. To do that, woul I have to play around with awk variables and print them all all at the end??

any advice would be great
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing from multiline output

Dear all, I have below "ldapsearch" output $ ldapsearch -D "CN=SVC-ACCOUNT,OU=SVC,OU=VDSI,OU=Non-Human,DC=Org,DC=com" -w secretword -H ldaps://org.com:636 -b DC=Org,DC=com -s sub uid=v00000 "(filter)" "displayName" "uid" "street" # extended LDIF # # LDAPv3 # base <DC=Org,DC=com> with... (7 Replies)
Discussion started by: baluchen
7 Replies

2. UNIX for Dummies Questions & Answers

Assigning ipv6 to bonding interface - getting old as well as changed ipv6 in ifconfig output

Hi, I have created a bonding bond1 interface with 6 Eth , mode=4. Recently i have changed my old ipv6 to new one and tried to restart as well as reload network service. Post which i can see old as well as changed ipv6 in ifconfig command output. Below are few files and command output for your... (1 Reply)
Discussion started by: omkar.jadhav
1 Replies

3. Shell Programming and Scripting

parsing ifconfig output

I'm trying to gather information on the interfaces on a large number of servers. If I run ifconfig I will get: eth0 Link encap:Ethernet HWaddr 00:50:56:A2:27:C1 inet addr:10.145.xxx.xxx Bcast:10.152.45.255 Mask:255.255.254.0 ----- eth1 Link... (2 Replies)
Discussion started by: C0ppert0p
2 Replies

4. Shell Programming and Scripting

Grabbing value from command output and monitoring for changes

Hi all, Very new to shell scripting so appreciate some help! There is a process count that I need to monitor, I have the AIX command that gives this value and I've cleaned it up with grep/awk so it only spits out the value I'm interested in: echo "psc -i 10050 -s RELOAD_SERVICE" | tmadmin... (14 Replies)
Discussion started by: monty77
14 Replies

5. Shell Programming and Scripting

assigning a multiline grep output which has been piped through sed to a shell variabl

Hi, I wish to format the output of a grep command in such a way that sed will be able to handle the newline characters held in the output. Since sed does not allow newlines to be contained in a replacement pattern, that means adding a backslash '\' character to the end of each line from... (8 Replies)
Discussion started by: timculhane
8 Replies

6. OS X (Apple)

Ifconfig output - help understanding flags 'Smart, Simplex', etc

Hi - Trying to understand a few things from an ifconfig -a output - can't seem to find info anywhere on the net. Specifically - looking to understand the following: Flags=8863 Smart Running (is this the same as UP) Simplex inet6 supported media: autoselect - does that imply the... (1 Reply)
Discussion started by: littlefrog
1 Replies

7. Solaris

How to know the global zonename from non-global zone?

It is easy to list all zones from global zones, but how to find out the global zone name from non-global zone? thx (11 Replies)
Discussion started by: honglus
11 Replies

8. UNIX for Dummies Questions & Answers

Grabbing a value from an output file

I am executing a stored proc and sending the results in a log file. I then want to grab one result from the output parameters (bolded below, 2) so that I can store it in a variable which will then be called in another script. There are more details that get printed in the beginning of the log file,... (3 Replies)
Discussion started by: hern14
3 Replies

9. Solaris

/sbin/zonename file giving me problems

I'm trying to install the recommended patch cluster on a x86 Solaris 10 box. I get this error: ERROR: /sbin/zonename cannot be found. install_cluster for 10_x86 patch cluster not applied. Exiting. I tried touching the file and it gave a different error of: expected argument.. anyone... (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

10. UNIX for Dummies Questions & Answers

Further question on 'ifconfig' output

I asked a similar question earlier and got a very good answer but a new doubt came up. This is a few lines of a '/sbin/ifconfig' command on my PC: RX packets:3781025 errors:0 dropped:0 overruns:0 frame:0 TX packets:1941909 errors:0 dropped:0 overruns:0 carrier:0 Does the RX and TX packets... (1 Reply)
Discussion started by: mint1981
1 Replies
Login or Register to Ask a Question