Parsing dig output consistently

Anand Buddhdev anandb at
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:

If I run:

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

I get output like this:

;			IN	SOA		3600	IN	SOA	( ... )
;			IN	SOA		3600	IN	SOA	( ... )
;			IN	SOA		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
;			IN	SOA		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?



More information about the bind-users mailing list