#!/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