|
|
发表于 2009-8-19 09:28:18
|
显示全部楼层
支持,不过就是反馈不是很好,无法直接复制粘贴使用,稍微修改了下
- #!/bin/bash
- #===============================================================================
- #
- # FILE: pacmanCompare
- #
- # USAGE: ./pacmanCompare
- #
- # DESCRIPTION:
- #
- # OPTIONS: -f -W -n -h
- # REQUIREMENTS: ---
- # BUGS: ---
- # NOTES: ---
- # AUTHOR: Myth
- # COMPANY:
- # VERSION: 0.2
- # CREATED: 08/8/2009 01:59:51 AM CST
- # REVISION: ---
- #===============================================================================
- Usage(){
- cat <<END
- Usage : pacmanCompare [-f file] [-W timeout] [-n Number] [-h]
- -n : specify the number of mirror to display
- -f : specify the pacman mirror file
- -W : set timeout
- -h : help
- END
- }
- timeout=5
- displayNumber=10
- mirrorFile="/etc/pacman.d/mirrorlist"
- while getopts hf:W:n: option
- do
- case $option in
- h)
- Usage
- exit 0
- ;;
- n)
- displayNumber=$OPTARG
- ;;
- W)
- timeout=$OPTARG
- ;;
- f)
- mirrorFile=$OPTARG
- ;;
- \?)
- Usage
- exit 1
- ;;
- esac
- done
- if [ ! -e "$mirrorFile" -o -d "$mirrorFile" ]
- then
- echo -e "Error while access pacman mirror file (Default is /etc/pacman.d/mirrorlist)\nExit !"
- exit 2
- fi
- cat $mirrorFile |sed '/^$/d' |grep 'Server =' >/tmp/mirrorTemp$$
- j=1
- all=`cat /tmp/mirrorTemp$$|wc -l`
- echo "Testing . Please wait ."
- cat /tmp/mirrorTemp$$|
- while read line
- do
- echo -n $j/$all $line "-->"
- line2=`echo $line| sed 's/.*Server\ =\ ftp:\/\/\([^\/]*\)\/.*/\1/' |sed 's/.*Server\ =\ http:\/\/\([^\/]*\)\/.*/\1/'`
- result=$(ping -c 1 -W $timeout "$line2" 2>/dev/null |grep 'bytes from'|cut -d' ' -f8 |cut -d'=' -f 2)
- echo -n ${result:-Can\'t connect\!}' ===>> '>>/tmp/speedTemp$$
- echo "$line" >>/tmp/speedTemp$$
- echo ${result:-Miss\!\!}
- ((j++))
- done
- echo
- rm /tmp/mirrorTemp$$
- grep -v "Can't connect" /tmp/speedTemp$$ |head -$displayNumber |sort -n
- grep -v "Can't connect" /tmp/speedTemp$$ |head -$displayNumber |sort -n |awk '{print $3" "$4" "$5}'
- rm /tmp/speedTemp$$
复制代码 |
|