30 lines
976 B
Bash
30 lines
976 B
Bash
#!/bin/sh
|
|
ping_timeout=1
|
|
test_time=3
|
|
tmpd=/tmp/mirrors-speed
|
|
urls=$(ftp -V -o - https://www.openbsd.org/ftp.html|grep -Eo '((http|https)://.*/OpenBSD/)'|uniq)
|
|
m_num=$(echo "$urls"|wc -l)
|
|
rm -rf $tmpd
|
|
mkdir $tmpd
|
|
_table="Mirror|Ping|MB/s"
|
|
_i=1
|
|
for url in $urls
|
|
do
|
|
printf "Testing [%3d/%3d] %s" $((_i++)) "$m_num" "$url"
|
|
_url="${url}snapshots/ports.tar.gz"
|
|
_host="$(echo "$url" | sed -ne 's|.*://\([^/]*\)/.*|\1|p')"
|
|
_tmpf=$tmpd/$_host
|
|
_ping=$(ping -w $ping_timeout -c 1 "$_host" 2>/dev/null | sed -nE 's/.*time=([0-9.]+).*/\1/p')
|
|
[ -z "$(echo $_ping)" ] && _ping="0"
|
|
timeout $test_time ftp -MVo "$_tmpf" "$_url" >/dev/null 2>&1
|
|
[ -s "$_tmpf" ] && {
|
|
_size=$(stat -f%z "$_tmpf" 2>/dev/null)
|
|
_speed=$(echo "scale=7; $_size / $test_time / 1024 / 1024" | bc)
|
|
} || _speed="0"
|
|
_row="$(printf "%s|%.3f|%f" "$url" "$_ping" "$_speed")"
|
|
_table="${_table}\n${_row}\n"
|
|
rm -f "$_tmpf"
|
|
printf "\033[2K\r"
|
|
done
|
|
echo "$_table" | sort -t'|' -n -k3 | column -t -s'|'
|
|
rm -rf $tmpd |