#!/bin/bash #Copyright 2002 William Stearns #Released under the GPL #One possible call: #if /usr/src/dns-check/dns-check ; then \ #echo Nothing has changed since the files were last written, good. \ #; else echo Content has either changed or been added. ; fi #If everything's OK, the script will produce no output at all. ConfFile='/etc/dns-check.conf' DataDir='/var/lib/dns-check/' RetVal=0 #True, everthing's unchanged from last time while [ -n "$1" ]; do case "$1" in -f) if [ -n "$2" ]; then ConfFile="$2" shift else echo Missing file name for '-f' option. Exiting. exit 1 fi ;; -d) if [ -n "$2" ]; then DataDir="$2" shift else echo Missing Data Directory for '-d' option. Exiting. exit 1 fi ;; *) echo Unrecognized command line option "$1" ;; esac shift done if [ ! -r "$ConfFile" ]; then echo Missing or unreadable configuration file "$ConfFile". Exiting. exit 1 fi if [ ! -d "$DataDir" ]; then echo Missing Data Directory "$DataDir". Exiting. exit 1 fi #Two less-thans is correct, really. exec 5<&0 < <(cat "$ConfFile" | sed -e 's/#.*//' | grep -v '^$' ) while read Server DnsObject Type ; do #echo Server "$Server" DnsObject "$DnsObject" Type "$Type" DigOut="`dig @$Server $DnsObject $Type | sed -e 's/;.*//' | grep -v '^$' | awk '{print $1, $3, $4, $5, $6, $7, $8, $9}' | sort`" if [ -f $DataDir/$Server-$DnsObject-$Type ]; then #Compare to exsting version if [ "$DigOut" != "`cat $DataDir/$Server-$DnsObject-$Type`" ]; then RetVal=1 #False, comething changed echo "$Server-$DnsObject-$Type mismatch!" echo Old version: cat "$DataDir/$Server-$DnsObject-$Type" | sed -e 's/^/ /' echo New Version: echo "$DigOut" | sed -e 's/^/ /' fi else RetVal=1 #False, new content added; someone should look into this. #Write it out for the first time for future comparison echo "Writing the following to $DataDir/$Server-$DnsObject-$Type for future compare." echo "$DigOut" | sed -e 's/^/ /' echo "$DigOut" | sort >"$DataDir/$Server-$DnsObject-$Type" fi done exec 0<&5 5<&- exit $RetVal