DNS Check Zones Script
At the Circus there are a number of people that have access to the DNS servers and not everyone understands the full extent of the damage they can do when they make improper changes to the configuration or zone files. One time we had a serious outage because there was an error in a zone file and DNS was returning non-authoritative answers for our zones. As a result I wrote this check_zones script to check all of the zones and email me with the results each night.
For those who are learning shell scripting the interesting thing to notice about this script is that I am actually reading two variables at the end of the cat command. Sometimes I forget how to do this and this is one of my library scripts for this exact reason. Once again, you got it off the web, your mileage may vary.
# 2007-02-14 Jud Bishop
# This script parses the /etc/named.conf file and checks every zone listed in it.
# Released under the GPL v2.
echo "" >/tmp/check_zone
echo "This is the list of bad zones." >>/tmp/check_zone
cat /etc/named.conf |egrep -w "zone|file" |cut -d \" -f 2 |sed '1~2 {N;s/\n/ /g}' |egrep -v "root|skip" |while read ZONE FILE
do
#echo "zone $ZONE file $FILE"
/usr/local/sbin/named-checkzone -k ignore $ZONE /var/named/$FILE
if [ $? -ne 0 ]
then
echo "$ZONE BAD" >>/tmp/check_zone
fi
done
echo "If there are no zones listed as BAD then there are no problems." >>/tmp/check_zone
cat /tmp/check_zone |mail -s "Zone Check" judson.bishop@circus.org