In my bash scripts I have been using something like:
until fping -u google.com; do echo "$0[$$] Network/DNS down?? $(date)" 1>&2 && sleep $(($RANDOM%(1 + ++trynum * 1) +1)).222; done
to test for online connectivity.
It halts in place, sleeping growing random intervals, until it can ping google.com again.
Problem: On some LANs ICMP pings are blocked altogether, although web pages are still reachable. What's a short way to test for this general case (firewall to outside)?
Based on that test I will switch over to an http-based test like the exit status of
curl -s google.com >/dev/null
if that is a good one.