summaryrefslogtreecommitdiff
path: root/ping-curl
diff options
context:
space:
mode:
authorDavid Timber <dxdt@dev.snart.me>2024-11-14 04:57:20 +0100
committerDavid Timber <dxdt@dev.snart.me>2024-11-14 05:03:42 +0100
commit03e678b8e3b643a29afcb0432dbe7ab3d4fcd78f (patch)
treecb32b307aa4c3726eaa92fd9a6e2130d9d2c94d9 /ping-curl
Initial commit
Diffstat (limited to 'ping-curl')
-rwxr-xr-xping-curl21
1 files changed, 21 insertions, 0 deletions
diff --git a/ping-curl b/ping-curl
new file mode 100755
index 00000000..ecde7217
--- /dev/null
+++ b/ping-curl
@@ -0,0 +1,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