summaryrefslogtreecommitdiff
path: root/ping-curl
blob: ecde7217d19a75d955d3f1ff7dc9d4f381642864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
export LC_ALL="C"
set -o pipefail

get_readtime () {
	grep -Ei '^real' | grep -Eio '[0-9]+\.[0-9]+'
}

do_ping () {
	time curl --connect-timeout 2 -sS "$1" -o /dev/null
}

for (( i = 0; i < 4; i += 1 ))
do
	ping=$(do_ping "$1" 2>&1)
	if [ $? -ne 0 ]; then
		echo "inf"
		exit 1
	fi
	echo "$ping" | get_readtime
done | uniq | sort | head -n1