Script for verifying zone files
Atkins, Brian (GD/VA-NSOC)
Brian.Atkins2 at va.gov
Fri Jul 23 15:19:28 UTC 2010
Thanks to everyone who replied to my questions yesterday. I gleaned some
very useful information from the conversations.
Using some of the suggestions, I kludged together another script. I'm
still fine tuning it. It works great for A and CNAME records, but I'm
tweaking the MX and NS record types.
Comments and critiques are appreciated.
Brian
=====
BEGIN
=====
#!/bin/bash
## named-checkzone_files.sh: verify records between two zone files.
########################################################################
#######
## CHANGE LOG
## Author Date Change
## B. Atkins 20100723 Started program...
########################################################################
#######
## VARIABLES
PATH=$PATH:/usr/sbin/:/usr/local/bin/
########################################################################
#######
## FUNCTIONS
usage() {
cat << EOF
$0 : Verify records between two zone files.
USAGE: $0 -f {FILE} -F {FILE} -z {ZONE} [-A|-a|-c|-m|-n] [-h (Prints
help]
OPTIONS:
-a Check only A records
-A Check ALL record types
-c Check only CNAME records
-f {FILE} Primary zone file {FILE}
-F {FILE} Secondary zone file {FILE}
-m Check only MX records
-n Check only NS records
-z {ZONE} Specify zone to verify
-h Prints this help file
EOF
exit $EXIT
}
make_dump() {
FILE=$1
ZONE=$2
EXTN=`echo ${FILE} | awk -F\/ '{print $NF}'`
[[ -e /tmp/${EXTN}.dumpdb ]] && rm -f /tmp/${EXTN}.dumpdb
echo -n "Creating DB file for ${FILE} ... " &&
named-checkzone -o /tmp/${EXTN}.dumpdb -D ${ZONE} ${FILE} >
/dev/null &&
echo OK || ( echo FAIL && echo -e "Failed to create DB for
${FILE}\nExiting ... " && exit 5 )
}
parse_file() {
FILE1=$1
FILE2=$2
ZONE=$3
TYPE=$4
EXTN1=`echo ${FILE1} | awk -F\/ '{print $NF}'`
EXTN2=`echo ${FILE2} | awk -F\/ '{print $NF}'`
grep "${TYPE}" /tmp/${EXTN1}.dumpdb |
awk '{print $1" "$NF}' |
while read LINE1
do LINE2=(`grep "${TYPE}" /tmp/${EXTN2}.dumpdb | awk
'{print $1" "$NF}' | grep -i "${LINE1[*]}"`)
if [[ -z ${LINE2} ]]
then LINE2=(`grep "${TYPE}" /tmp/${EXTN2}.dumpdb |
awk '{print $1" "$NF}' | grep -i "${LINE1[0]}"`)
if [[ -z ${LINE2} ]]
then echo "${LINE1[*]} ${TYPE}" >>
/tmp/${ZONE}.missing
else : ${LINE1[*]}
LAST1=$_
: ${LINE2[*]}
LAST2=$_
if [[ -z ${IGN} ]]
then if [[ ${LAST1} != ${LAST2} ]]
then echo "${LINE1[*]}
${TYPE}" >> /tmp/${ZONE}.missing
echo -e "\t${LINE2[*]}"
>> /tmp/${ZONE}.missing
else continue
fi
else continue
fi
fi
else continue
fi
done
}
########################################################################
#######
## MAIN PROGRAM
while getopts ":aAcf:F:hmnz:" opt
do case $opt in
a) TYPE="IN A" ;;
A) TYPE="ALL" ;;
c) TYPE="CNAME" ;;
f) FILE1=$OPTARG ;;
F) FILE2=$OPTARG ;;
m) TYPE="MX" ;;
n) TYPE="NS" ;;
z) ZONE=$OPTARG ;;
\?) usage
exit 99 ;;
:) echo "$0 : Option -$OPTARG requires and
argument."
EXIT=99
usage ;;
esac
done
[[ -z ${TYPE} ]] && TYPE="ALL"
[[ -z $FILE1 ]] && EXIT=1 && usage
[[ -z $FILE2 ]] && EXIT=2 && usage
[[ -z $ZONE ]] && EXIT=3 && usage
for FILE in ${FILE1} ${FILE2}
do make_dump ${FILE} ${ZONE}
done
[[ -s /tmp/${ZONE}.missing ]] && rm -f /tmp/${ZONE}.missing
if [[ ${TYPE} == "ALL" ]]
then for TYPE in "IN A" CNAME MX NS
do parse_file ${FILE1} ${FILE2} ${ZONE} "${TYPE}"
done
else parse_file ${FILE1} ${FILE2} ${ZONE} "${TYPE}"
fi
if [[ -s /tmp/${ZONE}.missing ]]
then echo "There are `wc -l /tmp/${ZONE}.missing | awk '{print $1}'`
bad or missing entries for ${ZONE}."
echo "Please review /tmp/${ZONE}.missing and take appropriate
action."
fi
exit 0
===
END
===
More information about the bind-users
mailing list