|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. 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
doneLet'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:
Quote:
Here's what the file output looks like: Quote:
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. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
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 |
| The Following 3 Users Say Thank You to Chubler_XL For This Useful Post: | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks, Chubler_XL! That was what was causing the problem!
![]() I ran the check as you suggested, just in case. Cheers! |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Nslookup!!! Please look up!!! | anishkumarv | Emergency UNIX and Linux Support !! Help Me!! | 4 | 05-05-2011 01:23 AM |
| nslookup: am I doing it right? | Abdulelah | Shell Programming and Scripting | 8 | 01-05-2011 02:13 PM |
| nslookup strangness | purest | IP Networking | 3 | 12-13-2007 07:42 AM |
| DNS client nslookup | xnightcrawl | UNIX for Advanced & Expert Users | 3 | 03-24-2006 02:29 PM |
| nslookup problem | xnightcrawl | UNIX for Advanced & Expert Users | 8 | 03-22-2006 09:07 PM |
|
|