Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dig return values

2,043 views
Skip to first unread message

Scott Haneda

unread,
May 22, 2009, 6:15:56 PM5/22/09
to
I have searched for "dig return codes" and also looked at the man
page, leading me to nothing definitive.

Does `dig` have return codes that I can use to make some form of
automated tests?

foo=`dig NS example.com @ns2.example.com +short +time=2 +tries=1`
echo $foo

; <<>> DiG 9.4.3-P1 <<>> NS example.com @ns2.example.com +short +time=2
+tries=1 ;;
global options: printcmd ;;
connection timed out; no servers could be reached

I do not know, nor would I want to have to know, all the possible
return strings I may get back. My needs are simple, I believe any
ANSWER of > 0 I would determine to be true, any timeout of any form I
would determine to be false.

Can anyone point me to docs on return codes, or is this going to
amount to string parsing? If it does, how much deviation on return
messages are there from the various dig versions that have been
released?

Thank you.
--
Scott * If you contact me off list replace talklists@ with scott@ *

_______________________________________________
bind-users mailing list
bind-...@lists.isc.org
https://lists.isc.org/mailman/listinfo/bind-users

David Forrest

unread,
May 22, 2009, 6:52:16 PM5/22/09
to
On Fri, 22 May 2009, Scott Haneda wrote:

> I have searched for "dig return codes" and also looked at the man page,
> leading me to nothing definitive.
>
> Does `dig` have return codes that I can use to make some form of automated
> tests?
>
> foo=`dig NS example.com @ns2.example.com +short +time=2 +tries=1`
> echo $foo
>
> ; <<>> DiG 9.4.3-P1 <<>> NS example.com @ns2.example.com +short
> +time=2
> +tries=1 ;;
> global options: printcmd ;;
> connection timed out; no servers could be reached
>
> I do not know, nor would I want to have to know, all the possible return
> strings I may get back. My needs are simple, I believe any ANSWER of > 0 I
> would determine to be true, any timeout of any form I would determine to be
> false.
>
> Can anyone point me to docs on return codes, or is this going to amount to
> string parsing? If it does, how much deviation on return messages are there
> from the various dig versions that have been released?
>
> Thank you.
>

my dig (version DiG 9.6.1b1) returns RC 0 on both an answer and a
connection timeout, and would seem to require a string parsing for a
useful branch. F9 64 system.

Dave

--
David Forrest
St. Louis, Missouri

Scott Haneda

unread,
May 22, 2009, 7:40:38 PM5/22/09
to
On May 22, 2009, at 3:52 PM, David Forrest wrote:

>> I have searched for "dig return codes" and also looked at the man
>> page, leading me to nothing definitive.
>>
>> Does `dig` have return codes that I can use to make some form of
>> automated tests?
>>
>> foo=`dig NS example.com @ns2.example.com +short +time=2 +tries=1`
>> echo $foo
>>
>> ; <<>> DiG 9.4.3-P1 <<>> NS example.com @ns2.example.com +short
>> +time=2
>> +tries=1 ;;
>> global options: printcmd ;;
>> connection timed out; no servers could be reached
>>
>> I do not know, nor would I want to have to know, all the possible
>> return strings I may get back. My needs are simple, I believe any
>> ANSWER of > 0 I would determine to be true, any timeout of any form
>> I would determine to be false.
>>
>> Can anyone point me to docs on return codes, or is this going to
>> amount to string parsing? If it does, how much deviation on return
>> messages are there from the various dig versions that have been
>> released?
>>
>> Thank you.
>>
>
> my dig (version DiG 9.6.1b1) returns RC 0 on both an answer and a
> connection timeout, and would seem to require a string parsing for a
> useful branch. F9 64 system.


Would you mind sharing with me how you tested that return value? I am
not seeing that bahavior at all, I get a true return for anything. I
have not been able to get false as of yet.

Thanks David.


--
Scott * If you contact me off list replace talklists@ with scott@ *

_______________________________________________

Chris Buxton

unread,
May 22, 2009, 8:03:57 PM5/22/09
to

0 is true (success), anything else is false (error). This allows for
multiple error codes and is standard for Unix commands.

To see the result of a command, use "echo $?" immediately afterward.
For example:

# foo=`dig`; echo $?
0

# foo=`dig @192.0.2.1`; echo $?
9

# foo=`dig @invalid.name`; echo $?
10

Those results come from dig version 9.4.3-P1. In the second example,
there is no host at the specified address. In the third example, the
name given for the server to query is invalid.

Chris Buxton
Professional Services
Men & Mice

Stephane Bortzmeyer

unread,
May 26, 2009, 9:19:10 AM5/26/09
to
On Fri, May 22, 2009 at 03:15:56PM -0700,
Scott Haneda <talk...@newgeo.com> wrote
a message of 32 lines which said:

> Does `dig` have return codes that I can use to make some form of
> automated tests?

Not for everything.

% dig +short SOA dummy.example && echo Success
Success

% dig +short @192.168.42.42 SOA dummy.example && echo Success
;; connection timed out; no servers could be reached

% dig @a.nic.fr AXFR dummy.example && echo Success

; <<>> DiG 9.5.1-P1 <<>> @a.nic.fr AXFR dummy.example
; (2 servers found)
;; global options: printcmd
; Transfer failed.
Success

So, some errors are detected but not all.

> I do not know, nor would I want to have to know, all the possible
> return strings I may get back. My needs are simple, I believe any
> ANSWER of > 0 I would determine to be true, any timeout of any form
> I would determine to be false.

Yes, but what about an answer of NOERROR,ANCOUNT=0, for instance:

dig @a.nic.fr A www.google.fr

Is it an error or not?

> Can anyone point me to docs on return codes, or is this going to amount
> to string parsing?

I do string parsing. As an example, see the script in
<http://www.bortzmeyer.org/recuperer-zone-dns.html> (the text is in
french but the comments in the script are in english).

if ! egrep "Transfer failed|connection timed out|Name or service not known|connection refused|network unreachable|host unreachable|communications error" $tmp > /dev/null; then
...

Scott Haneda

unread,
May 26, 2009, 3:28:16 PM5/26/09
to
On May 26, 2009, at 6:19 AM, Stephane Bortzmeyer wrote:

> On Fri, May 22, 2009 at 03:15:56PM -0700,
> Scott Haneda <talk...@newgeo.com> wrote
> a message of 32 lines which said:
>
>> I do not know, nor would I want to have to know, all the possible
>> return strings I may get back. My needs are simple, I believe any
>> ANSWER of > 0 I would determine to be true, any timeout of any form
>> I would determine to be false.
>
> Yes, but what about an answer of NOERROR,ANCOUNT=0, for instance:
>
> dig @a.nic.fr A www.google.fr
>
> Is it an error or not?

In my case, that would not be an error, my needs are for a rather
custom checking system.

>> Can anyone point me to docs on return codes, or is this going to
>> amount
>> to string parsing?
>
> I do string parsing. As an example, see the script in
> <http://www.bortzmeyer.org/recuperer-zone-dns.html> (the text is in
> french but the comments in the script are in english).

Very nice, thank you for that. This is a good start for me to see
what many of the possible return codes are that I need. My tool never
gets used in production, this is just something developers are going
to use. I installed for them DLZ, and get a lot of "DNS is down"
emails from the developers. In all reality, "database has bad data"
is more accurate. I just need a tool to show them what is going on,
without them having to learn all the replies dig may send back.

Thank you again for your link, most helpful.


--
Scott * If you contact me off list replace talklists@ with scott@ *

_______________________________________________

0 new messages