blob: a67d01469d10d091e33145f5725b626e08232d88 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
|