Sysadmin > UtilitIes > DnsTest

Howto check a domain in your script

dnstest

#! /bin/sh
printf "%-32s%15s    " $2 $3;
dig +short @$1 $2 $3 | grep $4 > /dev/null && echo '\t\033[32mok\033[39m' || echo '\t\033[31mfail\033[39m'

USAGE: dnstest SERVER IP TYPE TESTSTRING

script

dnstest $1 foo.de a 85.126.34.100
dnstest $1 bar.de a 85.126.34.101
dnstest $1 foo.de mx 85.126.34.112
dnstest $1 bla.de a 85.136.344.10

extractscript, extracts a testscript from db.zone.file

#!/usr/bin/gawk -f
BEGIN { print "#!/bin/sh" }
/ORIGIN/{ ORIGIN = $2 }
/\tSOA\t/ { print "dnstest $1 "$1"."ORIGIN" "$2" "$3 }
/IN SOA\t/ { print "dnstest $1 "$1ORIGIN" "$3" "$4 }
#/\tNS\t/ { print "dnstest $1 "ORIGIN" NS "$2 }
/^[a-z].*\t+A\t/ { print "dnstest $1 "$1"."ORIGIN" A "$3; HOST = $1 }
/^\t+A\t/ { print "dnstest $1 "HOST"."ORIGIN" A "$2 }
/^[a-z].*\t+CNAME\t/ { print "dnstest $1 "$1"."ORIGIN" CNAME "$3 }