Skip to content

Instantly share code, notes, and snippets.

@adam12
Created December 18, 2008 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adam12/37719 to your computer and use it in GitHub Desktop.
Save adam12/37719 to your computer and use it in GitHub Desktop.
Bash script to use scp to sync nameservers
#!/bin/bash
TEMPFILE=`mktemp -p /tmp`
HOSTNAME=`hostname`
MASTERS="xx.xx.xx.xx"
REMOTE_URI="dns@yy.yy.yy.yy"
for domain in `/bin/grep ^zone /etc/named.conf | /bin/grep "type master" | /bin/
awk '{print $2}' | /bin/awk -F\" '{print $2}'`
do
/usr/bin/printf "zone \"${domain}\" {\n type slave;\n file \"/var/named/slaves/${domain}.db\";\n masters { ${MASTERS}; };\n};\n\n"
done > ${TEMPFILE}
# Transfer File
scp ${TEMPFILE} ${REMOTE_URI}:${HOSTNAME}.conf
# Reload Remote Nameserver
ssh -t ${REMOTE_URI} 'sudo /etc/init.d/named reload'
# Cleanup
rm -f ${TEMPFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment