nslookup hanging


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting nslookup hanging
# 1  
Old 02-21-2012
nslookup hanging

Hey folks. Long time lurker, first time poster. I'm a bit of a newbie at "coding" (obviously, scripting is a teensy bit different than coding) and I've run into a problem that I just can't seem to get around.

I'm going through a list of servers to check their name, IP, reverse-NSLOOKUP name and ping status (whether pinging the server was successful). The thing is, every time I try to run through a list of servers, I get hung up on servers that aren't found in the domain.

I want to catch those servers and make sure I know they're not in the domain, but I don't want it to lock up the program that's running. Smilie

Here's my code:

Code:
for node_name in `cat /var/opt/OV/share/utils/node_check/log/myname/check_these_servers.txt`
do
  #Check for full name and IP address
  nslookup $node_name > /tmp/nslookup.out
  if [ $? = 0 ]
  then
    full_name=`cat /tmp/nslookup.out | grep  "Name:" | awk {'print $2'}`
    ip_address=`cat /tmp/nslookup.out | grep  "Address:" | awk {'print $2'}`
  else
    full_name="NONE"
    ip_address="NONE"
    reverse_name="NONE"
    ping_status="NONE"
    echo $node_name,$full_name,$ip_address,$reverse_name,$ping_status >> /var/opt/OV/share/utils/node_check/log/myname/nnm_check.csv
    # The "continue" here will be put back in when the script is working
    # continue
  fi
  #Do a reverse NSLOOKUP on IP address for full name
  nslookup $ip_address > /tmp/nslookup.out
  if [ $? = 0 ]
  then
    reverse_name=`cat /tmp/nslookup.out | grep  "Name:" | awk {'print $2'}`
  else
    reverse_name="NONE"
  fi
  #Check for successful ping
  ping $full_name -n 5 > /dev/null
  if [ $? = 0 ]
  then
    ping_status="YES"
  else
    ping_status="NO"
  fi
  #Print results
  echo $node_name,$full_name,$ip_address,$reverse_name,$ping_status >> /var/opt/OV/share/utils/node_check/log/myname/nnm_check.csv
done

Let's say I run a list of servers by using only the first part of their names (i.e. instead of "node_name1.domain-name.org", I use "node_name1"). I want NSLOOKUP to see if those servers are in the domain and for part of the resulting output to be the full name of that server instead of just the beginning part of it.

So I have a list that includes:

Quote:
node_name1
node_name2
node_name3
node_name4
...etc.
Let's also say that node_name3 is the server NSLOOKUP cannot locate. Here's what the output to my screen looks like:

Quote:
*** hostserver.domain-name.org can't find node_name3: Non-existent domain
And there it stays. The only way for me to stop it is to exit the command line entirely!

Here's what the file output looks like:

Quote:
node_name1,node_name1.domain-name.org,127.0.0.1 [I'm substituting a fake IP here for you guys],NODE_NAME1.domain-name.org,YES
node_name2,node_name2.domain-name.org,127.0.0.2 [I'm substituting a fake IP here for you guys],NODE_NAME2.domain-name.org,YES
In other words, the first two nodes are processed. When node_name3 comes around, the entire program hangs after it fails to find node_name3 in the domain.

Is it because I'm using only part of the hostname that I'm trying to look up? If this is so, why do the first two names work fine? Obviously I could delete the offending node name out of the list but I'd rather not have to do that every time there's a node name that doesn't work.

Anyone have any clues? And yes, I tried "timeout". It didn't work.
# 2  
Old 02-21-2012
It's probably because this grep "Address:" | awk {'print $2'}`is matching 2 lines of output

Code:
Server:  dc.domain-name.org
Address:  127.0.0.10
Name:    node_name1.domain-name.org
Address:  127.0.0.22

Calling nslookup 127.0.0.10 127.0.0.22 will probably hang waiting for a DNS response from 127.0.0.22 when it probably isn't a DNS server

You probably want the last occurance of Address: try:
Code:
ip_address=`awk '/Address:/{ I=$2} END{ print I}' /tmp/nslookup.out`

Note this also removes unneeded calls to cat and grep.

You should also test for blank full_name before using ping:

Code:
  [ -z "$full_name" ] && continue
  ping $full_name -n 5 > /dev/null

These 3 Users Gave Thanks to Chubler_XL For This Post:
# 3  
Old 02-22-2012
Thanks, Chubler_XL! That was what was causing the problem! Smilie

I ran the check as you suggested, just in case.

Cheers!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. Solaris

Further nslookup options if any !!

Hi , I have a requirement to find the aliases by doing an nslookup on the Cname. If i do an nslookup on the alias name i get the Cname , but i need the cname from alias name. eg: Hostname = acb.example.com Virtual name= abcvirtual.example.com nslookup abcvirtual.example.com will... (3 Replies)
Discussion started by: mpics66
3 Replies

5. Shell Programming and Scripting

nslookup output

Hi All, If I give the hostname followed by nslookup, I get the output like below, commandprompt>nslookup efgh Using /etc/hosts on: xyz looking up FILES Trying DNS Non-authoritative answer: Name: abcd Address: 47.47.47.47 Aliases: efgh I am not sure on the bolded ones. Can... (4 Replies)
Discussion started by: Rajakct84
4 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. UNIX for Advanced & Expert Users

nslookup problem

I am having trouble configuring BIND 8.3 on Solaris 9. When I run nslookup, I get this error/message: test# nslookup *** Can't find server name for address 192.168.1.31: Non-existent host/domain *** Default servers are not available I double checked everything and I can't figure this out. I... (8 Replies)
Discussion started by: xnightcrawl
8 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