Skip to content

Instantly share code, notes, and snippets.

@hashborgir
Last active February 22, 2023 02:42
Show Gist options
  • Save hashborgir/47443470d143f93814e4e034b428c85f to your computer and use it in GitHub Desktop.
Save hashborgir/47443470d143f93814e4e034b428c85f to your computer and use it in GitHub Desktop.
Ubuntu Fastest Mirror Finder by HB (Hash Borgir)
#!/bin/bash
# By HB
echo "Downloading latest Ubuntu mirrors.txt"
curl -o /tmp/mirrors.txt http://mirrors.ubuntu.com/mirrors.txt
input_file="/tmp/mirrors.txt"
fastest_url=""
fastest_time=9999
while read -r url; do
# Send a GET request to the URL using curl and measure the response time
response_time=$(curl --connect-timeout 5 --max-time 120 -w "%{time_total}" -o /dev/null "${url}ls-lR.gz")
# Output the URL and its latency
echo "URL: $url : $response_time seconds"
echo "------------------------"
# If the response time is less than the current fastest time, update the fastest URL and time
if (( $(echo "$response_time < $fastest_time" | bc -l) && $(echo "$response_time > 1" | bc -l) )); then
fastest_url="$url"
fastest_time="$response_time"
fi
done < "$input_file"
echo "Fastest URL: $fastest_url : $fastest_time seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment