Skip to content

Instantly share code, notes, and snippets.

@agarzon
Forked from adam12/update-slave.sh
Last active October 7, 2015 03:58
Show Gist options
  • Save agarzon/3102048 to your computer and use it in GitHub Desktop.
Save agarzon/3102048 to your computer and use it in GitHub Desktop.
Bash script to sync nameservers slave master automatically. Plesk 11 tested
#!/bin/bash
#Require root SSH access by authentication file
TEMPFILE=`mktemp -p /tmp`
HOSTNAME=`hostname`
MASTERS=`hostname -i`
REMOTE_URI="root@xxx.xxx.xxx.xxx"
SLAVE_PATH="/var/named/chroot/etc/"
for domain in `egrep '^zone' /etc/named.conf | egrep -iv "arpa|\"\." | egrep -iv "domain.com" | awk -F\" '{print $2}'`
do printf "zone \"${domain}\" {\n\t type slave;\n\t file \"/var/named/slaves/${domain}.db\";\n\t masters { ${MASTERS}; };\n};\n\n"
done > ${TEMPFILE}
#Fix permission error
chmod 644 ${TEMPFILE}
# Transfer File
scp ${TEMPFILE} ${REMOTE_URI}:${SLAVE_PATH}${HOSTNAME}.slaves
# Reload Remote Nameserver
ssh -t ${REMOTE_URI} 'service named restart'
# Cleanup
rm -f ${TEMPFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment