From e861c8b3db316285e989571bdb729e8107c2334c Mon Sep 17 00:00:00 2001 From: Dominika Liberda Date: Fri, 18 Jun 2021 08:57:18 +0000 Subject: [PATCH] * added double-pinging to avoid unnecessary notifications --- code/ping.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/code/ping.sh b/code/ping.sh index de84062..5da8b16 100755 --- a/code/ping.sh +++ b/code/ping.sh @@ -12,14 +12,21 @@ for i in $json; do res="$(ping -c 1 $addr > >(grep icmp_seq | sed -E 's/.*icmp_seq=.//'))" status=$? - if [[ "$status" == 0 ]]; then + if [[ "$res" == *"time"* ]]; then + res_parsed="$(grep -Eoh "time=.*ms" <<< "$res" | sed -E 's/time=//g;s/ms//g' | tr -d ' ')" + else + res_parsed='#' + fi + + # trying to ping for the 2nd time, as the interwebs may be flaky on the other side + + if [[ "$res_parsed" == "#" ]]; then + res="$(ping -c 1 $addr > >(grep icmp_seq | sed -E 's/.*icmp_seq=.//'))" if [[ "$res" == *"time"* ]]; then res_parsed="$(grep -Eoh "time=.*ms" <<< "$res" | sed -E 's/time=//g;s/ms//g' | tr -d ' ')" else res_parsed='#' fi - else - res_parsed='#' fi unset json_res