Parsing dig output consistently

Mark Andrews marka at isc.org
Wed Sep 17 11:57:04 UTC 2014


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

In message <54197448.1000801 at ripe.net>, Anand Buddhdev writes:
> 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
> _______________________________________________
> Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list
> 
> bind-users mailing list
> bind-users at 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: marka at isc.org


More information about the bind-users mailing list