-
Notifications
You must be signed in to change notification settings - Fork 19
/
test-datacenter.sh
executable file
·48 lines (43 loc) · 1.4 KB
/
test-datacenter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
bold=$(tput bold)
normal=$(tput sgr0)
better_ping=99999
better_datacenter=''
better_datacenter_name=''
max_ping=${1:-1}
datacenters="speedtest-lon1.digitalocean.com
speedtest-sfo1.digitalocean.com
speedtest-sfo2.digitalocean.com
speedtest-sfo3.digitalocean.com
speedtest-ams2.digitalocean.com
speedtest-ams3.digitalocean.com
speedtest-nyc1.digitalocean.com
speedtest-nyc2.digitalocean.com
speedtest-nyc3.digitalocean.com
speedtest-sgp1.digitalocean.com
speedtest-fra1.digitalocean.com
speedtest-tor1.digitalocean.com
speedtest-blr1.digitalocean.com"
while read -r line;
do
ping_avg=`ping -c $max_ping $line | tail -n1 | cut -d'=' -f2 | cut -d'/' -f2`
if [ -z "$ping_avg" ]
then
echo "Ping ${bold}${line}${normal}: not available"
continue
fi
echo "Ping ${bold}${line}${normal}: $ping_avg ms"
if [ $(echo "$ping_avg < $better_ping" | bc) -eq 1 ];
then
better_ping=$ping_avg
better_datacenter=$line
better_datacenter_name=`echo $line | cut -d'.' -f1 | cut -d'-' -f2`
fi
done <<< "$datacenters"
echo ""
echo "${bold}---------------------- Better Datacenter is -----------------------------------${normal}"
echo "${bold}Domain${normal}: $better_datacenter"
echo "${bold}Ping AVG${normal}: $better_ping ms"
echo "${bold}Name${normal}: $better_datacenter_name"
echo "${bold}-------------------------------------------------------------------------------${normal}"
echo ""