Skip to content

Instantly share code, notes, and snippets.

@bigbosst
Last active December 22, 2015 10:28
Show Gist options
  • Save bigbosst/6458626 to your computer and use it in GitHub Desktop.
Save bigbosst/6458626 to your computer and use it in GitHub Desktop.
Bash script to check named configuration and all zone files included in the configuration. This is a bit customized at the moment, only using single configuration file and skipping the first value in the loop
#!/bin/bash
#
# Checks the Named Configuration then
# Checks all zones in the named.conf
#
# Written by Troy Germain
# Base location of named configuration file
NAMEDCONF="/etc/named.conf"
# Base Path to the Zone Files
ZONEBASE="/var/named/"
# Command Path for named- commands
COMPATH="/usr/sbin/"
#CHROOT location if applicable, if not just use null definition
#CHROOT=""
CHROOT="/var/named/chroot"
eval ZONES=( $(sed -e 's/^[ \t]*//' ${CHROOT}${NAMEDCONF} | grep ^zone | grep -v '^//' | awk -F\" '{printf "%s ", $(NF-1)}') )
eval FILES=( $(sed -e 's/^[ \t]*//' ${CHROOT}${NAMEDCONF} | grep ^file | grep -v '^//' | awk -F\" '{printf "%s ", $(NF-1)}') )
${COMPATH}named-checkconf
if [[ $? != 0 ]]; then
echo "named.conf Configuration Check Failed!"
exit 1
fi
echo "Named Config Test Passed"
# Loop starts at 1 instead of 0 because of definition for named.ca
for (( LOOP=1; LOOP<${#ZONES[*]}; LOOP=LOOP+1 )); do
${COMPATH}named-checkzone ${ZONES[${LOOP}]} ${CHROOT}${ZONEBASE}${FILES[${LOOP}]}
if [[ $? != 0 ]]; then
echo "Check Failed! - ${ZONES[${LOOP}]} against ${CHROOT}${ZONEBASE}${FILES[${LOOP}]}"
exit 1
fi
done
echo "All Zone Files pass"
echo "All OK - Safe to Reload!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment