I made a cron that did a ping test on a DNS server to ensure networking. Something like this:
ping 126.96.36.199 -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 188.8.131.52 53 && echo 1 || echo 0
# Initial check to see if we are online
# How many times we should check if we're online - this 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.