#!/bin/bash #Copyright 2002 William Stearns #Released under the GPL. #FIXME - require-util Version='0.2' ConfFile='/etc/dns-check.conf' DataDir='/var/lib/dns-check/' RetVal=0 #True, everthing's unchanged from last time MaxTries=3 #Number of times we'll try to request a given record. usage () { echo "dns-check version $Version" >>/dev/stderr echo "Usage:" >>/dev/stderr echo " dns-check [-f ConfigFileName] [-d DataDirectory] [-h]" >>/dev/stderr echo " default config file is /etc/dns-check.conf">>/dev/stderr echo " default data directory is /var/lib/dns-check" >>/dev/stderr echo " -h shows this help" >>/dev/stderr echo "Exiting." >>/dev/stderr exit 1 } 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 ;; -h) usage ;; *) echo Unrecognized command line option "$1" usage ;; 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 TsigKey ; do CurrentTries=0 DigOut='' while [ "$DigOut" = '' ] && [ $CurrentTries -lt $MaxTries ]; do if [ -n "$TsigKey" ]; then #echo Server "$Server" DnsObject "$DnsObject" Type "$Type" TsigKey "$TsigKey" Attempt $CurrentTries >>/dev/stderr DigOut="`dig @$Server $DnsObject $Type -y $TsigKey | sed -e 's/;.*//' | grep -v '^$' | grep -v 'ANY.*TSIG' | awk '{print $1, $3, $4, $5, $6, $7, $8, $9}'`" else #echo Server "$Server" DnsObject "$DnsObject" Type "$Type" Attempt $CurrentTries >>/dev/stderr DigOut="`dig @$Server $DnsObject $Type | sed -e 's/;.*//' | grep -v '^$' | grep -v 'ANY.*TSIG'| awk '{print $1, $3, $4, $5, $6, $7, $8, $9}'`" fi #echo 'XX'"$DigOut"'XX' >>/dev/stderr CurrentTries=$[ $CurrentTries + 1 ] done if [ -f $DataDir/$Server-$DnsObject-$Type ]; then #Compare to exsting version if ! diff -q <(cat $DataDir/$Server-$DnsObject-$Type | sort) <(echo "$DigOut" | sort) >/dev/null 2>/dev/null ; then #if [ "`echo \"$DigOut\" | sort`" != "`cat $DataDir/$Server-$DnsObject-$Type | sort`" ]; then RetVal=1 #False, comething changed echo "$Server-$DnsObject-$Type mismatch!" diff -bd --unified=0 <(cat $DataDir/$Server-$DnsObject-$Type | sort) <(echo "$DigOut" | sort) | grep -v '^+++' | grep -v '^---' | grep -v '^@@' 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" >"$DataDir/$Server-$DnsObject-$Type" fi done exec 0<&5 5<&- exit $RetVal