Need to test if a host or your connection is up in a automated way?

HOST="example.com"
if ping -c1 -W1 $HOST; then
        echo "$HOST is up"
else
        echo "$HOST is unreachable"
fi

-W1 will determine for how long ping will wait before giving up.