diff options
author | Tar Committer <tar@ocjtech.us> | 2000-11-19 22:01:05 +0000 |
---|---|---|
committer | Tar Committer <tar@ocjtech.us> | 2000-11-19 22:01:05 +0000 |
commit | 1651adc35224e149715bd85af4ba108c5ee184bc (patch) | |
tree | f83b6af44ffb10f2c042b822b2f3469582a129ca /bin/control_rancid.in | |
parent | 3861ba4cf180eb01fd98a16f4502702ab217e56f (diff) | |
download | rancid-1651adc35224e149715bd85af4ba108c5ee184bc.tar.gz rancid-1651adc35224e149715bd85af4ba108c5ee184bc.tar.xz rancid-1651adc35224e149715bd85af4ba108c5ee184bc.zip |
Imported from rancid-2.0.tar.gz.rancid-2.0
Diffstat (limited to 'bin/control_rancid.in')
-rwxr-xr-x | bin/control_rancid.in | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/bin/control_rancid.in b/bin/control_rancid.in new file mode 100755 index 0000000..2acecc7 --- /dev/null +++ b/bin/control_rancid.in @@ -0,0 +1,259 @@ +#!/bin/sh +## +## +## Copyright (C) 1996 by Henry Kilmer. +## All rights reserved. +## +## This software may be freely copied, modified and redistributed without +## fee for non-commerical purposes provided that this copyright notice is +## preserved intact on all copies and modified copies. +## +## There is no warranty or other guarantee of fitness of this software. +## It is provided solely "as is". The author(s) disclaim(s) all +## responsibility and liability with respect to this software's usage +## or its effect upon hardware, computer systems, other software, or +## anything else. +## +## +# +# control_rancid $GROUP +# + +# Number of things par should run in parallel. +PAR_COUNT=5 + +# Must specify a group to run rancid +if [ $# -lt 1 ]; then + echo 'must specify group'; exit 1 +else + GROUP=$1 +fi +TMP=/var/tmp/rancid.$GROUP.$$ +DIR=$BASEDIR/$GROUP + +# Bail if we do not have the necessary info to run +if [ ! -d $DIR ] +then + ( + echo "$DIR does not exist." + ) | Mail -s "no $GROUP directory" rancid-admin-$GROUP + exit 1 +fi +if [ ! -f $DIR/router.db ] +then + ( + echo "$DIR/router.db does not exist." + ) | Mail -s "no $GROUP/router.db file" rancid-admin-$GROUP + exit 1; +elif [ ! -s $DIR/router.db ] +then + exit +fi + +# generate the list of routers we should try to fetch +cd $DIR +grep -v '^#' router.db > routers.db +cut -d: -f1,2 routers.db | sort -u > routers.all.new +diff routers.all routers.all.new > /dev/null 2>&1; RALL=$? +@PERLV_PATH@ -F: -ane '{($F[0] =~ tr@A-Z@a-z@,print "$F[0]:$F[1]\n") + if ($F[2] =~ /^down$/i);}' routers.db | sort -u > routers.down.new +diff routers.down routers.down.new > /dev/null 2>&1; RDOWN=$? +@PERLV_PATH@ -F: -ane '{($F[0] =~ tr@A-Z@a-z@,print "$F[0]:$F[1]\n") + if ($F[2] =~ /^up$/i);}' routers.db | sort -u > routers.up.new +diff routers.up routers.up.new > /dev/null 2>&1; RUP=$? + +if [ $RALL -ne 0 -o $RDOWN -ne 0 -o $RUP -ne 0 ] +then + ( + if [ $RUP -ne 0 ] ; then + if [ $RUP -eq 1 ] ; then + echo Routers changed to up: + comm -13 routers.up routers.up.new | sed -e 's/^/ /' + echo + elif [ -s routers.up.new ] ; then + echo Routers changed to up: + sed -e 's/^/ /' routers.up.new + echo + fi + fi + if [ $RDOWN -ne 0 ] ; then + if [ $RDOWN -eq 1 ] ; then + echo Routers changed to down: + comm -13 routers.down routers.down.new | sed -e 's/^/ /' + echo + elif [ -s routers.down.new ] ; then + echo Routers changed to down: + sed -e 's/^/ /' routers.down.new + echo + fi + fi + WC=`wc -l routers.all | sed -e 's/^ *\([^ ]*\) .*$/\1/'` + WCNEW=`wc -l routers.all.new | sed -e 's/^ *\([^ ]*\) .*$/\1/'` + if [ $RALL -eq 1 -a $WC -gt $WCNEW ] ; then + echo Deleted routers: + comm -23 routers.all routers.all.new | sed -e 's/^/ /' + fi + ) > routers.mail + + if [ -s routers.mail ] ; then + Mail -s "changes in $GROUP routers" rancid-admin-$GROUP < routers.mail + fi + rm -f routers.mail + + cd $DIR/configs + + # Add new routers to the CVS structure. + for router in `comm -13 $DIR/routers.up $DIR/routers.up.new` + do + OFS=$IFS + IFS=: + set $router + IFS=$OFS + router=$1 + + touch $router + cvs add -ko $router + cvs commit -m 'new router' $router + echo "Added $router" + done + echo + cd $DIR + +fi +mv routers.all.new routers.all +mv routers.down.new routers.down +mv routers.up.new routers.up +rm -f routers.db + +# cvs delete configs for routers not listed in routers.up. +cd $DIR/configs +for router in `find . \( -name \*.new -prune -o -name CVS -prune \) -o -type f -print | sed -e 's/^.\///'` ; do + grep "^$router:" ../router.db > /dev/null 2>&1 + if [ $? -eq 1 ]; then + rm -f $router + cvs delete $router + cvs commit -m 'deleted router' $router + echo "Deleted $router" + fi +done +cd $DIR + +# no routers, empty list or all 'down' +if [ ! -s routers.up ] +then + # commit router.db + cvs commit -m updates router.db > /dev/null + exit; +fi + +# Now we can actually try to get the configs +cd $DIR/configs + +# The number of processes running at any given time can be +# tailored to the specific installation. +echo "Trying to get all of the configs." +par -q -n $PAR_COUNT -c "rancid-fe \{}" $DIR/routers.up + +# This section will generate a list of missed routers +# and try to grab them again. It will run through +# $pass times. +pass=4 +round=1 +if [ -f $DIR/routers.up.missed ]; then + rm -f $DIR/routers.up.missed +fi +while [ $round -le $pass ] +do + for router in `cat $DIR/routers.up` + do + OFS=$IFS + IFS=':' + set $router + IFS=$OFS + router=$1; mfg=$2 + + if [ ! -s $router.new ] + then + echo "$router:$mfg" >> $DIR/routers.up.missed + rm -f $router.new + fi + done + + if [ -f $DIR/routers.up.missed ]; then + echo "=====================================" + echo "Getting missed routers: round $round." + par -q -n $PAR_COUNT -c "rancid-fe \{}" $DIR/routers.up.missed + rm -f $DIR/routers.up.missed + round=`expr $round + 1` + else + echo "All routers sucessfully completed." + round=`expr $pass + 1` + fi +done +echo + +# Make sure that all of the new configs are not empty. +for config in *.new +do + if [ ! -s $config ] + then + rm -f $config + fi +done + +# Now that we have the new configs, rename them to their proper +# name. +rename 's/.new$//' *.new + +# This has been different for different machines... +# Diff the directory and then checkin. +cd $DIR +#cvs diff -c3 >$TMP.diff +#cvs diff -C 3 >$TMP.diff +# Change the output of a unified diff to make it a bit more readable. +cat > $TMP.sedf << EOF +/^RCS file: /d +#/^retrieving revision /d +/^--- /d +/^+++ /d +s/^\([-+ ]\)/\1 / +EOF +cvs -f diff -u -4 | sed -f $TMP.sedf >$TMP.diff +rm -f $TMP.sedf + +cvs commit -m updates + +# Mail out the diffs (if there are any). +if [ -s $TMP.diff ]; then + sendmail -t <<EMAIL +To: rancid-$GROUP +Subject: $GROUP router config diffs +Precedence: bulk + +`cat $TMP.diff` +EMAIL +fi + +# If any machines have not been reached within the last $OLDTIME +# hours, mail out a list of them. +cd $DIR/configs +rm -f $DIR/routers.failed +if [ "X$OLDTIME" = "X" ] ; then + OLDTIME=24 +fi +@PERLV_PATH@ -F: -ane "{\$t = (stat(\$F[0]))[9]; print \`ls -ld \$F[0]\` + if (time() - \$t >= $OLDTIME*60*60);}" $DIR/routers.up | sort -u > $DIR/routers.failed +if [ -s $DIR/routers.failed ] +then + ( + cat <<END +The following routers have not been successfully contacted for more +than $OLDTIME hours. + +END + cat $DIR/routers.failed + ) | Mail -s "config fetcher problems - $GROUP" rancid-admin-$GROUP +fi + +# Cleanup +rm -f $TMP.diff $TMP.lst |