'for' loop advice needed....!!


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users 'for' loop advice needed....!!
# 1  
Old 03-19-2010
Bug 'for' loop advice needed....!!

Scenario:

Command used to capture IPs on a host:

Code:
/usr/sbin/ifconfig -a | grep "inet" | egrep -v "inet6|0.0.0.0|192.168.100.2" | awk '{print $2}'

Following for loop used to capture interface names:

Code:
for INTERFACE in `/usr/sbin/ifconfig -a | nawk '$1 ~ /:$/ && $1 {sub(":$", "", $1); print $1}'`
        do
        val=`/usr/sbin/ifconfig $INTERFACE | grep -w "@@Host IPs.IP Addresses@@"|awk '{print $2}'`
        if [ $val = "@@Host IPs.IP Addresses@@" ]
        then
            echo $INTERFACE
        fi    
done

@@Host IPs.IP Addresses@@ comes from the above command used to capture IPs.

Iteration is taken care by my engine.

Issue:

I have a solaris host where 'ifconfig -a' shows 7 loopback interfaces with same IP.

Take a look at following

Code:
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 <ZONE>
        inet 127.0.0.1 netmask ff000000
lo0:2: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone <ZONE>
        inet 127.0.0.1 netmask ff000000
lo0:4: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone <ZONE>
        inet 127.0.0.1 netmask ff000000
lo0:6: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone <ZONE>
        inet 127.0.0.1 netmask ff000000
lo0:7: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone <ZONE>
        inet 127.0.0.1 netmask ff000000
lo0:8: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone <ZONE>
        inet 127.0.0.1 netmask ff000000

As you can see,these interfaces have same IP and this is where the 'for' loop is fumbling.

Look at the o/p i am getting:
Code:
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0lo0:1lo0:2lo0:4lo0:6lo0:7lo0:8       N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0lo0:1lo0:2lo0:4lo0:6lo0:7lo0:8       N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0lo0:1lo0:2lo0:4lo0:6lo0:7lo0:8       N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0lo0:1lo0:2lo0:4lo0:6lo0:7lo0:8       N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0lo0:1lo0:2lo0:4lo0:6lo0:7lo0:8       N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0lo0:1lo0:2lo0:4lo0:6lo0:7lo0:8       N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0lo0:1lo0:2lo0:4lo0:6lo0:7lo0:8       N/A


This is what i want :

Code:
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0		N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0:1		N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0:2		N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0:4		N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0:6		N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0:7		N/A  
<HOST> 127.0.0.1       255.0.0.0       <DNS>      2010-03-16      lo0:8		N/A

Can anyone suggest a better way ?

Regards
Abhi
# 2  
Old 03-22-2010
Bug

Any idea/suggestion/advice pls ...!!


Regards
Abhi
# 3  
Old 03-24-2010
What is it you're trying to gather? a zone to loopback interface mapping?

maybe this..?

Code:
for zone in `zoneadm -i|grep -v global`
do
echo "*****************"
zlogin $zone ifconfig -a|grep lo|awk -F: '{print $1":"$2}'
done

# 4  
Old 03-25-2010
Bug

thanks erice !!

i am trying to capture all the IPs and respective interfaces on a host...both are two columns of a csv file....

Regards
Abhi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Scripting advice needed

Evening all, Im trying to get a script that will: Select the most 3 recent files in a specific directory Run a command on them (like chmod) Ask of you would like to continue Copy the files to another directory If a linux guru could help me out, it would be very much appreciated. Thanks... (2 Replies)
Discussion started by: Wiggins
2 Replies

2. Shell Programming and Scripting

Advice needed on using Script with NOHUP

All, I would like to know my below requirement can be achieved in any way in Shell Scripting? I will make this requirement of mine as understandable as I can. Requirement: I wrote a script 'my.script' which gets user-input tablenames and puts the same into an array. Also I get other inputs... (6 Replies)
Discussion started by: bharath.gct
6 Replies

3. Shell Programming and Scripting

'for' loop advice needed ....!!

/usr/sbin/ifconfig -a | grep "inet" | grep -v "inet6" | grep -v "127.0.0.1" | grep -v "0.0.0.0"|grep -v "192.168.100.2" | awk '{print $2}' I use above command to get IP addresses on AIX boxes.Values coming here are set to a variable "Host IPs.IP Addresses" in my fingerprinting engine. ... (4 Replies)
Discussion started by: ak835
4 Replies

4. Programming

urgent advice needed - gcc

what does the statement : static char a = "a"; store in the executable image. ?? I need to make a command line parameter exist AFTER the program finishes execution.. so that when i run the code next time ( without recompiling ).. i can work with the paramter.. for example: ... (5 Replies)
Discussion started by: a.k.aFireknight
5 Replies

5. Filesystems, Disks and Memory

LVM resizing advice needed

Hi I have a CentOS 5 server with LVM. / and /home are low on disk space. I have ~12Gb available on /usr I plan to resize /usr and add the available space to the other 2 partitions. Please advice me on any precautions I need to take. Any problem if you have faced doing similar stuff and... (0 Replies)
Discussion started by: yunusyb
0 Replies

6. Linux

GUI builder advice needed ......

Hello all, I need to develop an application that would be used as a simulator to test various custom algorithms. As I have never embarked on this kind of work, I need some advice: 1. Which GUI library to use in Linux, GTK+ or FLTK? The simulator application needs to output various... (2 Replies)
Discussion started by: fox_hound_33
2 Replies

7. Shell Programming and Scripting

eval problem.. advice needed!

Hi I need some major help with eval I have a statement using eval: read input eval variable$input=”something” Now I want to use the “variable$input” in some commands but I don't know how to call it without replacing the $input with the command line value (which I obviously can't do). ... (1 Reply)
Discussion started by: Cactus Jack
1 Replies

8. Solaris

Storage hardware - advice needed

I realise this is an odd request - but I need advice please.. I have two server - in different geographical locations.. The have 2 local 72gb disks which are mirrored. I need to get storage added to increase both to 300gb in total each and this needs to be mirrored in case of failure. The... (2 Replies)
Discussion started by: frustrated1
2 Replies

9. Solaris

Using San storage - advice needed

Thinking of using our San for network backups.. Have a Netra 240 being installed and planning to get some space on our San. Do you know what software is used to access the San from my server or what I would need to do? I know how to connect to local storage, disk arrays etc but not sure what... (1 Reply)
Discussion started by: frustrated1
1 Replies

10. Linux

programming advice needed....

i'm a grad student taking a UNIX course and a networks course (i have a background in C++ and JAVA). i'm trying to combine the two classes. My questions stems from a networks programming homework assignment below: "Using the operating system and language of your choice, develop a program to... (5 Replies)
Discussion started by: trostycp
5 Replies
Login or Register to Ask a Question