Compare IP Address from nslookup and file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare IP Address from nslookup and file
# 1  
Old 08-18-2011
Compare IP Address from nslookup and file

Hi,

I am trying to compare IP address of a server using nslookup with IP address in a file (serverlist). And if there is a difference in IP, it should send an email.
But there is some error in the pgm... Please help...

Code:
#!/usr/bin/ksh

for server in `cat serverlist`
do
        old_ip=`cat serverlist | awk -F\; '{ print $2 }'`
        ser_name=`cat serverlist | awk 'BEGIN{ FS=";";RS = "\n\n" }{ print $1 }'`
        for j in "$ser_name\n"
        do
        curr_ip=`nslookup $j | grep Address | sed -n '2p' | cut -d: -f2`
        done
        for i in $old_ip
        do
        if [ $curr_ip == $old_ip ]
        then
                echo "IP is SAME"
        else
                echo "IP is DIFFERENT"
         fi
        done
done[/SIZE]

<serverlist> file format

abc.xyz.aaa.com;123.234.345.123
bbb.xxx.ccc.com;456.765.234.987

Last edited by Franklin52; 08-19-2011 at 03:16 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 08-18-2011
are you getting an error when you run the script or the logic is wrong and it is not printing out what you want?
# 3  
Old 08-18-2011
$ ./ip_compare.sh
IP is DIFFERENT
IP is DIFFERENT
IP is DIFFERENT
IP is DIFFERENT

Output is wrong.....I dont have a difference in IP..
# 4  
Old 08-18-2011
Looks like there is a leading space when you "cut" that ip from nslookup, replace curr_ip with this:

Code:
curr_ip=`nslookup $j | grep Address | sed -n '2p' | cut -d: -f2|sed 's/^[ \t]*//'`

# 5  
Old 08-18-2011
still the same output...wrong one Smilie
# 6  
Old 08-18-2011
replace the following :

Code:
if [ $curr_ip == $old_ip ]

with:

Code:
if [[ "$curr_ip" == "$old_ip" ]]

keep the above sed change intact.

if you still get wrong results, replace #!/usr/bin/ksh with #!/usr/bin/ksh -x to enable trace and post the trace output.
# 7  
Old 08-18-2011
I cannot separate the server name to nslookup.
while comparing in if [["new_ip" == "$old_ip"]]
it is taking both IP from the file to compare with new IP.

+ [[ 123.234.345.123 = 123.234.345.123
456.765.234.987 ]]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk nslookup

Hi, I have a rather simple awk statement to perform an nslookup on a file (list of IPs). If the lookup yields a result, then it sends it to a file. If no result, there is no output. I've been trying to use !NR or !NF with an if statement to make the output state "NA" if there is no result,... (5 Replies)
Discussion started by: umang2382
5 Replies

2. Solaris

nslookup command

hi, I am new in Solaris 10 , i am installing a software in solaris 10, while performing pre requisite nslookup command should return without error, and the IP address and host should match those listed in the etc/hosts file, but nslookup command show the below error , can anybody tell me how i... (4 Replies)
Discussion started by: zeeshan047
4 Replies

3. Emergency UNIX and Linux Support

Nslookup!!! Please look up!!!

Hi all Nslookup command returns!!!! Code: nslookup 10.91.44.29 Server: 127.0.0.1 Address: 127.0.0.1#53 29.44.91.in-addr.arpa name = station1.example.com Code: nslookup station1.example.com Server: 127.0.0.1 Address: 127.0.0.1#53 Name: ... (4 Replies)
Discussion started by: anishkumarv
4 Replies

4. Shell Programming and Scripting

nslookup: am I doing it right?

Hi guys, I'm back to get some help again :) I have a file that has a list of IP addresses, and I use nslookup in my script to resolve hostnames of those IPs. the problem I'm facing is that I not all the hostnames got resolved! and I don't know why. sometimes the same duplicate IP returns a... (8 Replies)
Discussion started by: Abdulelah
8 Replies

5. Shell Programming and Scripting

Fast algorithm to compare an IP address against a list of IP sections?

I have two files: file1: 41.138.128.0 41.138.159.255 location 41.138.160.0 41.138.191.255 location 41.138.192.0 41.138.207.255 location 41.138.208.0 41.138.223.255 location 41.138.224.0 41.138.239.255 location 41.138.240.0 41.138.255.255 location 41.138.32.0 ... (7 Replies)
Discussion started by: kevintse
7 Replies

6. IP Networking

nslookup command?

Hai guys, In which way does the command,"nslookup", will be helpful? Please give me examples. Thanks. (5 Replies)
Discussion started by: Felicia23
5 Replies

7. Shell Programming and Scripting

script to compare two files of mac address

Hi I need to write a bash shell script. I have two separate text files. One file contains a list of MAC addresses taken from a network scan, the other contains a list of MAC addresses for our currently-managed devices. How can I compare these two files, and output a list of addresses that have... (6 Replies)
Discussion started by: borderblaster
6 Replies

8. Shell Programming and Scripting

NSLOOKUP script

Hi Anyone know of a quick and simple way to script an NSLOOKUP's from a list/text file? Thanks, Gav (1 Reply)
Discussion started by: gavcollins
1 Replies

9. UNIX for Dummies Questions & Answers

nslookup on linux ???

Hi I usually use solaris but Im working right now with a Linux box and I cannot find the nslookup command. Does Linux use this command or have an other one to do dns querys?? Thanks and sorry for such a dumb question.. :) (2 Replies)
Discussion started by: piltrafa
2 Replies

10. UNIX for Advanced & Expert Users

named and nslookup

Guys , Am using Linux - Red Hat 6.1 . My DNS and nslookup command was working fine and ppl. can resolve through this server . but i changed something in /etc/named.conf , that stopped the DNS . The named proccess is working , but nslookup command is not , i get this error message : ... (3 Replies)
Discussion started by: tamemi
3 Replies
Login or Register to Ask a Question