#!/bin/bash ping -nq -W 1 -c 1 1.1.1.1 > /dev/null 2>&1 state=$? oldstate=$state while true; do ping -nq -W 1 -c 1 1.1.1.1 > /dev/null 2>&1 state=$? if [[ $oldstate -ne $state ]]; then if [[ $state -eq 0 ]]; then echo "Device went back online" else echo "Device went offline" fi fi oldstate=$state sleep 5 done