I made a cron that did a ping test on a DNS server to ensure networking. Something like this:
ping 220.127.116.11 -c 1 -i .2 -t 60 > /dev/null 2>&1
if [ ONLINE -eq 0 ]; then
Recently I've used something like this:
netcat -z -w 5 18.104.22.168 53 && echo 1 || echo 0
# Initial check to see if we're online
# How many times we should check if we're online - prevents infinite looping
# Initial starting value for checks
# Loop while we're not online.
while [ $IS_ONLINE -eq 0 ];do
# We're offline. Sleep for a bit, then check again
CHECKS=$[ $CHECKS + 1 ]
if [ $CHECKS -gt $MAX_CHECKS ]; then
if [ $IS_ONLINE -eq 0 ]; then
# We never were able to get online. Kill script.
# Now we enter our normal code here. The above was just for online checking
This isn't the MOST elegant - I'm not sure how else to check via a simple command or file on the system, but this has worked for me when needed.