From 624658b8991650401852c60ee9c73615a6c22e89 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Mon, 28 Nov 2022 14:08:45 -0500 Subject: new command pingwatch --- dot/local/bin/pingwatch | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 dot/local/bin/pingwatch diff --git a/dot/local/bin/pingwatch b/dot/local/bin/pingwatch new file mode 100755 index 0000000..a67d014 --- /dev/null +++ b/dot/local/bin/pingwatch @@ -0,0 +1,41 @@ +#!/bin/bash +loud= +target=${1:-2601:401:8200:2d4c:c6a5:6c8c:1304:bcf7} + +process() +{ + state= + while true + do + if read -t 5 line + then + if [ "$loud" ] + then + printf '%s\n' "$line" + fi + case "$line" in + PING*) continue ;; + esac + if [ "$state" = on ] + then + continue + else + date +'%c Online.' + state=on + fi + elif [ $? -gt 128 ] # read timeout + then + if [ "$state" = off ] + then + continue + else + date +'%c Offline.' + state=off + fi + else # non-timeout read error + break + fi + done +} + +ping -n "$target" | process -- cgit v1.2.3