summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdot/local/bin/pingwatch41
1 files changed, 41 insertions, 0 deletions
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 @@
1#!/bin/bash
2loud=
3target=${1:-2601:401:8200:2d4c:c6a5:6c8c:1304:bcf7}
4
5process()
6{
7 state=
8 while true
9 do
10 if read -t 5 line
11 then
12 if [ "$loud" ]
13 then
14 printf '%s\n' "$line"
15 fi
16 case "$line" in
17 PING*) continue ;;
18 esac
19 if [ "$state" = on ]
20 then
21 continue
22 else
23 date +'%c Online.'
24 state=on
25 fi
26 elif [ $? -gt 128 ] # read timeout
27 then
28 if [ "$state" = off ]
29 then
30 continue
31 else
32 date +'%c Offline.'
33 state=off
34 fi
35 else # non-timeout read error
36 break
37 fi
38 done
39}
40
41ping -n "$target" | process