A pyramid of little scripts: nsdig

October 4, 2006

One of my DNS diagnostic tools is a program called nsdig; it makes a query to all of the authoritative servers for a zone. This makes it convenient to both look for inconsistencies and see what the authoritative servers are saying, as opposed to whatever is filtering through your local caching servers.

As another one of my little shell scripts, and as a practical example of how little utilities stack on top of each other to everyone's benefit, here's nsdig and its component bits:

; cat nsdig
#!/bin/sh
case "$#" in
   3) nssrc=$3;;
   2) nssrc=$2;;
   *) echo usage: nsdig T WHAT [DOM] 1>&2
      exit 1;;
 esac
 for i in `nsaddrs $nssrc`; do
     echo "---- $i ----"
     dig +norecurse $1 $2 @$i
 done

(The third argument is necessary for cases like 'nsdig a www.foo.com foo.com'.)

; cat nsaddrs
#!/bin/sh
addr `sdig ns $1` | sort -u

; cat addr
#!/bin/sh
for i in "$@"; do
  sdig a $i
done

; cat sdig
#!/bin/sh
exec dig +short "$@"

(dig is the standard DNS lookup utility. Honesty compels me to admit that the version of addr that I actually use is a much more complicated Python program with various additional features that are irrelevant for nsaddr's usage.)

The one building block that is not as useful as it could be is dig, which sometimes insists on sprinkling its output with extraneous bits. (For example, even the short dig output for TXT queries has quotes around the results, which are almost always surplus.)


Comments on this page:

By Dan.Astoorian at 2006-10-05 12:39:37:
   case "$#" in
      3) nssrc=$3;;
      2) nssrc=#2;;

"nssrc=$2", not "nssrc=#2", surely?

By cks at 2006-10-05 15:31:09:

Oh the embarrassment, Dan, and thanks for catching that; I've corrected it in the entry now. This should teach me a valuable lesson about a) not directly importing the live scripts and b) not testing the versions of the scripts in entries.

(Copies of programs in text are famously subject to these problems, and I know it, and I still got caught.)

Written on 04 October 2006.
« Some numbers for modern disk performance
Thoughts on machine identity »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Oct 4 23:22:07 2006
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.