Parsing dig output consistently

Anand Buddhdev anandb at ripe.net
Wed Sep 17 11:45:12 UTC 2014


Hello people,

I've been trying to figure out how to use dig in a shell script to send
a bunch of queries, and then parse the output with awk. I have a file
called "myzones" containing the zones I want to query:

example.com
example.org
example.net

If I run:

dig @server -t soa +norec +noall +question +answer -f myzones

I get output like this:

;example.com.			IN	SOA
example.com.		3600	IN	SOA	( ... )
;example.org.			IN	SOA
example.org.		3600	IN	SOA	( ... )
;example.net.			IN	SOA
example.net.		3600	IN	SOA	( ... )

What I'm missing is the header and flags section, because I also want to
see the RCODE and the flags. However, I don't know which option to dig
will give me:

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41562
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;example.com.			IN	SOA
example.com.		3600	IN	SOA	( ... )

Actually, I am not really interested in the answer either. All I want
are lines showing me the RCODE and the question, which I can match up
and determine whether a server is returning NOERROR, REFUSED or SERVFAIL
for a given zone. Is this possible?

Regards,

Anand


More information about the bind-users mailing list