Finding the nearest CVSUP server
Tagged:  •    •  
This shell script will find the nearest (relative to ping latency) CVSUP server to get your source updates from
#!/bin/sh
# Copyright (C) 2004 Andrew Loree
# $Id: cvsupfinder.sh,v 1.1 2004/02/14 02:13:45 andy Exp $
############################################################################
#
# cvsupfinder.sh - Runs ping a ping test against cvsup1.freebsd.org thru
#	cvsup16.freebsd.org and returns the name of the server that had
#	the best average response time.  Pass in the word silent to 
#	use withing a cvsup command using backticks
#
############################################################################
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
#############################################################################
# Version History:
#   1.0  - Initial Release
#############################################################################
SILENT=""
case "$1" in
silent)
	SILENT="YES"
	;;
esac

if [ -z $SILENT ]
then
	echo "Finding fastest cvsup server"
fi

if [ -e /tmp/cvstest ]
then
	rm /tmp/cvstest
fi
for i in `jot 17`; do
	cvsserver="cvsup${i}"
	if [ -z $SILENT ]
	then
		echo $cvsserver
	fi
	t=`ping -c 1 cvsup${i}.freebsd.org | grep time | awk -F= '{print $4}'| awk '{print $1}'`
	# | sed 's/.//'`
	if ! [ -z $t ]
	then
		echo "$t $cvsserver" >> /tmp/cvstest
	fi
done

SERVER=`sort -n /tmp/cvstest | head -1 | awk '{print $2}'`
PINGTIME=`sort -n /tmp/cvstest | head -1 | awk '{print $1}'`

if [ -z $SILENT ]
then
	echo "$SERVER.freebsd.org is the fastest ping at $PINGTIME ms"
else
	echo "$SERVER.freebsd.org"
fi
 


AttachmentSize
cvsupfinder.sh2.06 KB