Bash script to (more or less) reliably check if the internet is up

Posted by João Portela on Stack Overflow See other posts from Stack Overflow or by João Portela
Published on 2010-05-27T15:02:37Z Indexed on 2010/05/27 15:11 UTC
Read the original article Hit count: 213

Filed under:
|
|

I need a bash script to put in a cron job that every minute checks if the internet is up.

This is how I did it:

#! /bin/sh

host1=google.com
host2=wikipedia.org
curr_date=`date +"%Y%m%d%H%M"`

echo -n "${curr_date};"
((ping -w5 -c3 $host1 || ping -w5 -c3 $host2) > /dev/null 2>&1) && echo "up" || (echo "down" && exit 1)

How would you do it? Which hosts would you ping?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about linux

Related posts about bash