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. :wall:

Here's my 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:

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

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:

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.

It's probably because this grep "Address:" | awk {'print $2'}` is matching 2 lines of output

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:

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:

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

Thanks, Chubler_XL! That was what was causing the problem! :smiley:

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

Cheers!