Operating System - HP-UX
1752600 Members
3942 Online
108788 Solutions
New Discussion юеВ

Need shell script to find IPs when instance names are known

 
SOLVED
Go to solution
Shivkumar
Super Advisor

Need shell script to find IPs when instance names are known

Hi,

I have a file having instance names.

Say for example:
abc
def
lmn
opr
xyz

I want to find IP corrresponding to each of the instance and want to write in a new file
having instance and its IP.

Can someone suggest a shell script ?

Thanks,
Shiv
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: Need shell script to find IPs when instance names are known

Hi Shiv:

Perhaps you want:

#!/usr/bin/sh
while read LAN X do
ifconfig ${LAN}|awk 'NR==1 {LAN=$1};NR==2 {print LAN,$2}'
done < fileofnames

Regards!

...JRF...
Shivkumar
Super Advisor

Re: Need shell script to find IPs when instance names are known

In case i want to use nslookup on each of the instance having listed in a text file. Then how the script will look like ?
Mel Burslan
Honored Contributor

Re: Need shell script to find IPs when instance names are known

would you be looking for something like this then ?

for i in `cat /tmp/fileofinstances`
do
name=`ifconfig $i | awk 'NR==2 {print LAN,$2}'| \
nslookup|grep ^Name|cut -d: -f2| tr -s " "|cut -d" " -f 2`
echo $i" "$name
done

________________________________
UNIX because I majored in cryptology...