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

Parsing dig output consistently

392 views
Skip to first unread message

Anand Buddhdev

unread,
Sep 17, 2014, 7:45:12 AM9/17/14
to bind-...@lists.isc.org
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

Mark Andrews

unread,
Sep 17, 2014, 7:57:04 AM9/17/14
to bind-...@isc.org

awk '$5 == "status:" { rcode = $6 } $3 == "SOA" { print $1, rcode }'
> _______________________________________________
> Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list
>
> bind-users mailing list
> bind-...@lists.isc.org
> https://lists.isc.org/mailman/listinfo/bind-users
--
Mark Andrews, ISC
1 Seymour St., Dundas Valley, NSW 2117, Australia
PHONE: +61 2 9871 4742 INTERNET: ma...@isc.org

Anand Buddhdev

unread,
Sep 17, 2014, 8:32:51 AM9/17/14
to bind-...@isc.org
On 17/09/2014 13:57, Mark Andrews wrote:

Hi Mark,

> awk '$5 == "status:" { rcode = $6 } $3 == "SOA" { print $1, rcode }'

So with "+noall +comments +question" and this bit of awk, I can get a
pretty list containing ";zone RCODE," pairs :)

Thanks!

Anand
0 new messages