応答時間に基づいてウェブサイトを並べ替える

応答時間に基づいてウェブサイトを並べ替える

このスクリプトを次のように使用したいと思います。

cat websites.txt | latency | sort -n

今私はやっています:

test.sh

# Sort websites by their response time

# get the list of websites
websites=$(cat websites.txt)

# loop through the websites
for website in $websites
do
    # get the response time of the website
    response_time=$(curl -o /dev/null -s -w %{time_total} $website)

    # print the response time
    echo "Response Time for $website is $response_time seconds"
done

これを使用して、レイテンシが最も短いフェデレーションされたインスタンスを見つけたいと思います。

ベストアンサー1

#!/bin/bash


fun1 () {
# get the list of websites
websites=$(cat websites.txt)

# loop through the websites
for website in $websites
do
    # get the response time of the website
    response_time=`curl -o /dev/null -s -w %{time_total} $website`
    # print the response time
    echo "Response Time for $website is $response_time seconds"
done
}

fun1 | sort -k6 -n

sortだからそれがすることは、現在のスクリプト全体を関数に置き換えてから、6番目のキーを要素にパイプすることです。key()オプションは-kフィールド/行番号を使用します。

おすすめ記事