婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Shell腳本實(shí)現(xiàn)檢測Cygwin最快的鏡像站點(diǎn)

Shell腳本實(shí)現(xiàn)檢測Cygwin最快的鏡像站點(diǎn)

熱門標(biāo)簽:寧波智能外呼系統(tǒng)公司 安裝外呼系統(tǒng)費(fèi)用 地圖標(biāo)注輻射圖案 曲阜400電話辦理 申請公司400電話要注意什么 衛(wèi)星地圖標(biāo)注地名 聯(lián)通電話機(jī)器人怎么接 奧維互動(dòng)地圖標(biāo)注參數(shù) 電銷機(jī)器人 劍魚

這是一個(gè) shell 腳本,所以首先你需要安裝一個(gè)基本的 Cygwin 環(huán)境,當(dāng)然還有 curl。

原理很簡單,先從 cygwin.com 下載最新的 mirrors.lst 鏡像列表,簡單處理一下后,利用 curl 以此檢測每個(gè)站點(diǎn)的連接速度,并將結(jié)果記錄下來,最后再排個(gè)序,顯示出最快的幾個(gè)站點(diǎn)。

在使用的過程中,我發(fā)現(xiàn)檢測到的最快的 mirror,實(shí)際上使用速度并不一定是最快的,這可能和服務(wù)器有關(guān)系,畢竟 curl 檢測的時(shí)間只是讀取 mirror 首頁的時(shí)間。不過每個(gè) mirror 一般都有兩組服務(wù)器——http ftp,如果其中一個(gè)速度不怎么樣,那么可以選擇另外一個(gè)試試看。

復(fù)制代碼 代碼如下:

#!/bin/sh
 
# cygwin-mirrors.sh
# 該腳本用于查找 Cygwin 的最快鏡像
 
timeout=5           # 超時(shí)時(shí)間
mirrors_count=5     # 顯示最快的幾個(gè)鏡像
PROG=`basename $0`  # 程序名稱
 
## 顯示 usage
_usage() {
    echo "Usage: ${PROG} [-t timeout>] [-p mirrors_count>] [-h]"
    exit
}
 
## 檢查參數(shù)并賦值
_assign() {
    if [ "$1" == "timeout" -o "$1" == "mirrors_count" ]; then
        if [[ "$2" =~ ^[[:digit:]]+$ ]]; then
            let $1=$2
        else
            echo "$1 should be a number"
            exit 1
        fi
    fi
}
 
## 處理參數(shù)
while getopts ":t:p:h-:" optval
do
    case "$optval" in
        t)   _assign timeout ${OPTARG} ;;
        p)   _assign mirrors_count ${OPTARG} ;;
        h)   _usage ;;
        "-") echo "Unknown option: '--${OPTARG}'" >2;            _usage ;;
        ":") echo "Option '-${OPTARG}' requires an argument" >2; _usage ;;
        "?") echo "Unknown option: '-${OPTARG}'" >2;             _usage ;;
        ## Should not occur
        *)   echo "Unknown error while processing options" >2;   _usage ;;
    esac
done
shift $(expr ${OPTIND} - 1)
 
## 檢查用戶是否安裝了 curl
CURL=`which curl 2> /dev/null`
[ -z "$CURL" ] (echo "Need to install the curl package."; exit 1)
 
## 讀取鏡像站點(diǎn)
mirrors=`curl --silent http://cygwin.com/mirrors.lst | cut -d';' -f1`
 
## 使用 CURL 依次檢測時(shí)間
results=''
for mirror in $mirrors; do
    echo -n "Checking ${mirror} ... "
    time=`curl -m $timeout -s -o /dev/null -w %{time_total} $mirror`
    if [ "$time" = "0.000" ]; then
        echo -e "\e[31mfail\e[0m"
    else
        echo -e "\e[32m$time\e[0m"
        results="${results}\e[32m${time}\e[0m - ${mirror}\n"
    fi
done
 
echo -e "\n檢測結(jié)果:"
echo -e $results | sort -n | sed '1d' | head -$mirrors_count
 
# vim: set expandtab tabstop=4 shiftwidth=4:

您可能感興趣的文章:
  • 自動(dòng)化下載并檢測ftp文件備份的shell腳本
  • 用來檢測輸入的選項(xiàng)$1是否在PATH中的shell腳本
  • shell腳本實(shí)現(xiàn)實(shí)時(shí)檢測文件變更
  • VBS腳本寫的Windows硬件檢測工具分享
  • Linux Shell腳本實(shí)現(xiàn)檢測tomcat
  • Shell腳本實(shí)現(xiàn)檢測進(jìn)程是否正在運(yùn)行
  • PowerShell腳本實(shí)現(xiàn)檢測網(wǎng)絡(luò)內(nèi)主機(jī)類型
  • 腳本批量檢測網(wǎng)站是否存活

標(biāo)簽:大興安嶺 安康 仙桃 江西 遵義 大慶 三門峽 上饒

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Shell腳本實(shí)現(xiàn)檢測Cygwin最快的鏡像站點(diǎn)》,本文關(guān)鍵詞  Shell,腳本,實(shí)現(xiàn),檢測,Cygwin,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Shell腳本實(shí)現(xiàn)檢測Cygwin最快的鏡像站點(diǎn)》相關(guān)的同類信息!
  • 本頁收集關(guān)于Shell腳本實(shí)現(xiàn)檢測Cygwin最快的鏡像站點(diǎn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 大方县| 屯门区| 敖汉旗| 法库县| 宣恩县| 宁海县| 石门县| 通道| 新密市| 青铜峡市| 道真| 新龙县| 唐山市| 宜川县| 湟中县| 当阳市| 长岛县| 西乡县| 广汉市| 津市市| 灵山县| 剑阁县| 儋州市| 科技| 丰宁| 延寿县| 尚志市| 建宁县| 琼中| 连山| 龙岩市| 建水县| 琼中| 三明市| 白玉县| 拉萨市| 通河县| 铜鼓县| 建阳市| 灵丘县| 潮安县|