* added double-pinging to avoid unnecessary notifications

master
Dominika Liberda 2021-06-18 08:57:18 +00:00
parent 8406cbedf8
commit e861c8b3db
1 changed files with 10 additions and 3 deletions

View File

@ -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