* added double-pinging to avoid unnecessary notifications

This commit is contained in:
Dominika Liberda 2021-06-18 08:57:18 +00:00
parent 8406cbedf8
commit e861c8b3db

View file

@ -12,15 +12,22 @@ 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
fi
unset json_res
declare -A json_res