Skip to content

Instantly share code, notes, and snippets.

@blessani
Created May 20, 2014 09:56
Show Gist options
  • Save blessani/aedac637530db9dee686 to your computer and use it in GitHub Desktop.
Save blessani/aedac637530db9dee686 to your computer and use it in GitHub Desktop.
Compare old/new TinyDNS zone file
#!/bin/bash
ZONE_FILES=()
NEW_NAMESERVER="" # eg. ns1.sonassihosting.com
for ZONE in ${ZONE_FILES[@]}; do
TITLE="Testing $ZONE"
TITLE_LEN=${#TITLE}
HEADER=$(for i in $(seq 1 $TITLE_LEN); do echo -n "="; done)
echo -e "\n$HEADER\n$TITLE\n$HEADER\n"
grep -vE "^#" $ZONE | ack-grep '^(.)([^:]+):' --output='$1 $2' | while read TYPE RECORD; do
case $TYPE in
".")
TYPE=
;;
"@")
TYPE=mx
;;
"+")
TYPE=a
;;
"C")
TYPE=cname
;;
":"|"'")
TYPE=txt
;;
esac
[[ "$TYPE" == "" ]] && continue
OLD=$(dig +short $RECORD $TYPE | tr '[:upper:]' '[:lower:]')
NEW=$(dig +short $RECORD $TYPE @$NEW_NAMESERVER | tr '[:upper:]' '[:lower:]')
echo -n "Checking $RECORD ($TYPE) ... "
[[ "$(echo $OLD | md5sum)" == "$(echo $NEW | md5sum)" ]] && echo "OK" || ( echo -e "ERROR\n Old: $OLD\n New: $NEW" )
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment