1833772 Members
2093 Online
110063 Solutions
New Discussion

rval of nslookup

 
SOLVED
Go to solution
Kevin Wright
Honored Contributor

rval of nslookup

does anyone know why nslookup is always returning a return value of 0, whether it works or not?

nslookup host
rval=$?
if [[ $rval -eq 0 ]];then
echo 'it works'
else
echo 'no host'
fi

this always returns 'it works' no matter what host yo put in??

I use the rval with grep all the time, and 0 is success, 1 is fail. can this not be done with nslookup?
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor
Solution

Re: rval of nslookup

Hi Kevin:

There's no rule that you must exit with a zero/non-zero value. Convention dictates that zero (0) is success and (1) is failure. Two (2) is often used to denote a "warning". However, as a writer I could just as easily exit(0), regardless.

...JRF...
Victor BERRIDGE
Honored Contributor

Re: rval of nslookup

Hi,
Well I would say the command succeeded although it did not find what you were looking for (the command did work) so why not test on something like "can't find host" ?

My 2 cents

ALl the best
Victor
Joseph C. Denman
Honored Contributor

Re: rval of nslookup

Victor is correct. The command did succeed. Just because it did not find anything does not cause failure. FTP works the same way. It always ends in rval 0.

...jcd...
If I had only read the instructions first??
Bill Hassell
Honored Contributor

Re: rval of nslookup

nslookup has many different functions and the rules it follows determine whether it produces the result you are looking for. For instance, nslookup may be told to look in /etc/hosts first and does not find the hostname so it asks the DNSD server and finds it. Is that a failure, a success or half a failure?

nslookup is one of many ways to resolve an address. A better way for your question is the little known command: getip


Bill Hassell, sysadmin
A. Clay Stephenson
Acclaimed Contributor

Re: rval of nslookup

Hi Kevin:

Welcome to UNIX, just because the rules and conventions are there doesn't mean the developer has to follow them. Sometimes you have to do string patterm matching (and this is one of them); sometimes you have to look at the 3rd column of the 10th line of output to
know it a command succeeded.

If you really want to be frustrated try using remsh.

Regards, Clay
If it ain't broke, I can fix that.
Kevin Wright
Honored Contributor

Re: rval of nslookup

I get it now, pretty stupid huh, the command worked fine, therefore the exit of 0, just because it did not find a host does not mean the command failed..
thanks, you know someone could really learn alot from you guys.
Magdi KAMAL
Respected Contributor

Re: rval of nslookup

Hi Kevin,

I would say, all hp-ux commands which got internal menus ( like lanadmin, ftp, nslookup, rgy_edit, ...) have the same behaviour like what you discribe : Return exit 0 upon completion whether succeeded or not ( that's mean finshes with succes but don't mean the what it was doing is succeeded ! ).

But usual hp-ux commands ( not divisible commands ) behave like what you supposed initially. If a command no not succeed what it is intended to do so the return code will be different from 0.

Magdi