#!/bin/sh ########################################################## # # # Written 6/18/08 by Jeff Schroeder # # ########################################################## # # # # # pushnamedconf.sh - Push out a script to update the # # # named.conf and run it. # # # # # # # # ########################################################## # $Id: pushnamedconf.sh 68111 2008-10-13 22:19:41Z jschroeder $ TIMEOUT=15 # Seconds before initial connection times out MASTER_DNS_SERVER=master.dns.server # VIP for master dns server MASTER_DATACENTER=$(echo $MASTER_DNS_SERVER | awk -F. '{print $2}') MASTER_DNS=$(host -t A $MASTER_DNS_SERVER | awk '{print $NF}') SYNC_SCRIPT="$(which bindconfsync-slave.sh)" SSH_OPTIONS="-o ConnectTimeout=$TIMEOUT -o PasswordAuthentication=no" usage() { cat << EOF >&2 Usage: $(basename $0) [OPTIONS] Push out bindconfsync-slave.sh to all nameservers to update named.conf -l - List servers -c [CLUSTER] - Only push changes to [CLUSTER] -p - Only push changes to primary servers ie: ns1.*.mtt -b - Only push changes to backup servers ie: ns2.*.mtt -n - Display what would happen but don't actually do it EOF exit 1 } # To get a new list of CLUSTERS, run this command: # awk -F'["]' '/zone.*mtt/{if ($2 ~ ".mtt$" && $2 !~ "core" ) print $2}' /var/named/chroot/etc/named.conf # Strip out clusters that don't have local dns servers CLUSTERS="chi01 chi02 dub01 fra01 lax01 lax02 lon01 lon02 nyc01 nyc02 nyc04 nyc05 nyc06 sin01 tyo01" # getopts is braindumb about gnu style options if [ "$1" = "--help" ]; then usage fi # Do some sanity checks on the script used to sync the named.conf if [ ! -x "$SYNC_SCRIPT" -a -e "$SYNC_SCRIPT" ]; then chmod 755 "$SYNC_SCRIPT" elif [ ! -e "$SYNC_SCRIPT" ]; then echo "FATAL: $SYNC_SCRIPT missing" >&2 exit 1 fi while getopts 'pbnlhc:' opt; do case "$opt" in p) PATTERN='^ns1\.' ;; b) PATTERN='^ns2\.' ;; l) LIST=true ;; n) DRYRUN=true ;; c) CLUSTERS="$OPTARG" ;; h) usage ;; *) usage ;; esac done for cluster in $CLUSTERS ; do if [ "$cluster" = "$MASTER_DATACENTER" ]; then echo "${HOSTNAME:-$(hostname -f)}: Skipping $MASTER_DATACENTER" >&2 continue fi dns_servers="$dns_servers $(host -l ${cluster}.mtt $MASTER_DNS | egrep "${PATTERN:-^ns[12]\.}" | \ awk '{if ($1 ~ "^ns") print $1}' | \ sed -e 's/ /\n/g' | \ grep -v '^$')" done # Show a prompt if no arguments are given. This prevents accidents if [ $# -eq 0 ]; then echo "Pushing changes to these dns servers:" printf "%s\n" $dns_servers until [ ! -z "$input" ]; do echo -n "Are you sure you want to continue? y/n: " read input done input=$(echo $input | tr [A-Z] [a-z] | cut -c1) # Exit on anything that doesn't start with y [ "$input" = "y" ] || exit 1 fi if [ ! -z "$LIST" ]; then echo "Pushing changes to these dns servers:" printf "%s\n" $dns_servers exit 0 fi if [ ! -z "$DRYRUN" ]; then scp="echo scp" ssh="echo ssh" else scp=scp ssh=ssh fi for server in $dns_servers; do tput init if [ ! "$DRYRUN" ]; then echo "${HOSTNAME:-$(hostname -f)}: pushing configuration out to $server" fi $scp -q $SSH_OPTIONS "$SYNC_SCRIPT" root@${server}:$SYNC_SCRIPT $ssh -t $SSH_OPTIONS -l root $server "$SYNC_SCRIPT" 2>&1 | \ egrep -v 'Connection to.*closed.' done