#!/bin/bash loud=${VERBOSE} default_target=marble.tj5tzswz7isfavggdjsiwxdjswrg6tadlzuf3j3q.ed25519.cryptonomic.net if [ $# = 1 ] then target=$1 else target=$(dig -taaaa +short +answer $default_target || echo 2601:401:8200:2d4c:84f4:6bdc:963c:fde2) fi if [ "$VERBOSE" ] then echo "target: $target" >&2 fi process() { state= while true do if read -t 5 line then case "$line" in 'PING'* | *'Address unreachable') continue ;; esac if [ "$loud" ] then printf '%s\n' "$line" fi 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