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
[Expired for bind9 (Ubuntu) because there has been no activity for 60
days.]
** Changed in: bind9 (Ubuntu)
Status: Incomplete = Expired
--
You received this bug notification because you are a member of Ubuntu
Server Team, which is subscribed to bind9 in Ubuntu.
It's a work around but I'd still expect dig to return a non-zero number
sometimes.
--
You received this bug notification because you are a member of Ubuntu
Server Team, which is subscribed to bind9 in Ubuntu.
https://bugs.launchpad.net/bugs/854705
Title:
dig returns 0 regardless of result of
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,
Sorry it should return 1 instead if the query failed.
--
You received this bug notification because you are a member of Ubuntu
Server Team, which is subscribed to bind9 in Ubuntu.
https://bugs.launchpad.net/bugs/854705
Title:
dig returns 0 regardless of result of query
To manage
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).
--
You received this bug notification because you are a member of Ubuntu
Server Team, which is subscribed to bind9 in
I would expect dig to respond in this manner:
dig +short www.google.com echo SUCCESS || echo FAILURE
--
You received this bug notification because you are a member of Ubuntu
Server Team, which is subscribed to bind9 in Ubuntu.
https://bugs.launchpad.net/bugs/854705
Title:
dig returns 0
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