#!/usr/bin/env bash connected="" disconnected="" while true; do if [[ $(ping -c1 8.8.8.8) ]]; then echo "$connected"; sleep 10 else echo "$disconnected"; sleep 1 echo "$connected"; sleep 1 fi done