dig returns 0 regardless of result of query

Bug #854705 reported by Lars Noodén
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bind9 (Ubuntu)
Expired
Wishlist
Unassigned

Bug Description

/usr/bin/dig returns 0 regardless of whether the query was successful or not. It should return 0 instead if the query failed.

Revision history for this message
Lars Noodén (larsnooden) wrote :

Sorry it should return 1 instead if the query failed.

Revision history for this message
Stéphane Bortzmeyer (stephane+launchpad-o) wrote :

What do you mean "failed"? NXDOMAIN? SERVFAIL? Timeout? They are very different things. I would strongly object to returning 1 when the answer is NXDOMAIN (the query succeeded).

Revision history for this message
Lars Noodén (larsnooden) wrote :

I would expect dig to respond in this manner:

dig +short www.google.com && echo SUCCESS || echo FAILURE

Revision history for this message
Dave Walker (davewalker) wrote :

I'm not convinced the exit code can be handled how you want it. A lookup that returns NXDOMAIN was a successful lookup, so IMO shouldn't return an exit code of non-zero.

is this not a valid work around for what you want?
dig www.google.com | grep NOERROR 1>/dev/null && echo SUCCESS || echo FAILURE

Changed in bind9 (Ubuntu):
importance: Undecided → Wishlist
status: New → Incomplete
Revision history for this message
Lars Noodén (larsnooden) wrote :

It's a work around but I'd still expect dig to return a non-zero number sometimes.

Revision history for this message
Stéphane Bortzmeyer (stephane+launchpad-o) wrote :

You never specified what you want. "Sometimes"??? Is that a specification? For instance, NXDOMAIN is *not* an error.

May be you actually want something like:

 ADDRS=$(dig +short www.google.com); if [ -z "$ADDRS" ]; then echo FAILURE; else echo SUCCESS; fi

For another example of testing dig results, see the script in http://www.bortzmeyer.org/files/try-get-zone.sh

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for bind9 (Ubuntu) because there has been no activity for 60 days.]

Changed in bind9 (Ubuntu):
status: Incomplete → Expired
Revision history for this message
Jeff Silverman (jeffsilverm) wrote :

It turns out that the host command will do what you want.

jeffs@jeffs-desktop:~$ host www.g00gle.com 8.8.8.8
Using domain server:
Name: 8.8.8.8
Address: 8.8.8.8#53
Aliases:

Host www.g00gle.com not found: 2(SERVFAIL)
jeffs@jeffs-desktop:~$ echo $?
1 <===================================================
jeffs@jeffs-desktop:~$ host www.google.com 8.8.8.8
Using domain server:
Name: 8.8.8.8
Address: 8.8.8.8#53
Aliases:

www.google.com has address 216.58.216.164
www.google.com has IPv6 address 2607:f8b0:400a:805::1013
jeffs@jeffs-desktop:~$ echo $?
0
jeffs@jeffs-desktop:~$ host www.google.com 10.82.34.123
;; connection timed out; no servers could be reached
jeffs@jeffs-desktop:~$ echo $?
1
jeffs@jeffs-desktop:~$

Revision history for this message
Alexey Kopytko (sanmai) wrote :

You can use grep to detect that dig returns a non-empty string

    dig +short www.google.not-com | grep -v -e '^$' > /dev/null && echo SUCCESS || echo FAILURE

prints FAILURE

    dig +short www.google.com | grep -v -e '^$' > /dev/null && echo SUCCESS || echo FAILURE

prints SUCCESS

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.