"host" Return Codes

Barry Finkel b19141 at achilles.ctd.anl.gov
Mon May 21 18:23:49 UTC 2007

I wrote, in part:

>>I have a question about the: "host" command - specifically the return 
>>code.  Here is the output of two executions - one on Solaris 10 and
>>the other on Ubuntu:
>>     atalanta% uname -a
>>     SunOS atalanta.it.anl.gov 5.10 Generic_125100-05 sun4u sparc
>>           SUNW,Sun-Fire-V240
>>     atalanta% host aaa.anl.gov
>>     Host aaa.anl.gov not found: 3(NXDOMAIN)
>>     atalanta% echo $status
>>     0
>>     atalanta% which host  
>>     /usr/sbin/host
>>     atalanta%
>>     vm20% uname -a
>>     Linux vm20.it.anl.gov 2.6.15-28-amd64-k8 #1 SMP PREEMPT
>>           Tue Mar 13 20:57:54 UTC 2007 x86_64 GNU/Linux
>>     vm20% host aaa.anl.gov
>>     Host aaa.anl.gov not found: 3(NXDOMAIN)
>>     vm20% echo $status
>>     1
>>     vm20% which host
>>     /usr/bin/host
>>     vm20%
>>Note that Solaris 10 gives a return code of 0, while Ubuntu gives an
>>expected return code of 1.  I did not see anything in the BIND 9.3.4
>>CHANGES file about host and return codes.  I do not see any string
>>within the host executable that tells me the origin of the source.

and Chris Thompson <cet1 at hermes.cam.ac.uk> replied:

>It would appear by comparison with the contemporaneous "dig" that the
>Solaris 10 /usr/sbin/host is from 9.2.4. And it does indeed have the
>exit code 0 after NXDOMAIN behaviour that you observe.
>So, what else is new? It's (almost) never worth agonising about versions
>of BIND and its friends bundled with the operating system, whichever
>flavour of operating system that is. Build your own. 

I have done some research with the source (host.c) from various older
versions of BIND that I have built over the years.

     8.3.4 set the return code.
     9.2.4 did not set the return code.
     9.3.2 set the return code.

I am assuming that it was 9.3.0 that included the code to set the
return code, even though I saw nothing in the CHANGES file.

The problem I have is this - I build BIND for my DNS servers, but
we have one web application where we want to use the "host" command,
and I would prefer not to build BIND just to get a "dig" that sets the
return code properly.  The application has to rely on the return code;
it will not parse any human-readible messages such as

     Host aaa.anl.gov not found: 3(NXDOMAIN)

I am trying to rely on the "dig" supplied by the operating system
Barry S. Finkel
Computing and Information Systems Division
Argonne National Laboratory          Phone:    +1 (630) 252-7277
9700 South Cass Avenue               Facsimile:+1 (630) 252-4601
Building 222, Room D209              Internet: BSFinkel at anl.gov
Argonne, IL   60439-4828             IBMMAIL:  I1004994

More information about the bind-users mailing list