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

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

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

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

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

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

在使用的過(guò)程中,我發(fā)現(xiàn)檢測(cè)到的最快的 mirror,實(shí)際上使用速度并不一定是最快的,這可能和服務(wù)器有關(guān)系,畢竟 curl 檢測(cè)的時(shí)間只是讀取 mirror 首頁(yè)的時(shí)間。不過(guò)每個(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 依次檢測(cè)時(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檢測(cè)結(jié)果:"
echo -e $results | sort -n | sed '1d' | head -$mirrors_count
 
# vim: set expandtab tabstop=4 shiftwidth=4:

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

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

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Shell腳本實(shí)現(xiàn)檢測(cè)Cygwin最快的鏡像站點(diǎn)》,本文關(guān)鍵詞  Shell,腳本,實(shí)現(xiàn),檢測(cè),Cygwin,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Shell腳本實(shí)現(xiàn)檢測(cè)Cygwin最快的鏡像站點(diǎn)》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Shell腳本實(shí)現(xiàn)檢測(cè)Cygwin最快的鏡像站點(diǎn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 丹东市| 旌德县| 京山县| 乌审旗| 中江县| 绿春县| 韩城市| 麻阳| 渑池县| 富裕县| 特克斯县| 浪卡子县| 观塘区| 连平县| 保亭| 仁寿县| 夏津县| 漳州市| 大悟县| 濮阳市| 屯门区| 卢湾区| 英山县| 陇川县| 惠安县| 彰化市| 竹溪县| 嘉定区| 曲周县| 东乡族自治县| 正蓝旗| 纳雍县| 乐陵市| 罗山县| 阜城县| 嘉义市| 大港区| 桓仁| 四子王旗| 原阳县| 宁乡县|