Run command once a day, but only when internet connection is available.

The first step is defining what you mean by "having an Internet connection".

For instance, simply seeing whether a particular link is up or not, or whether a particular link has an IP address, may not be sufficient.

One fairly reliable way — the sort of thing browsers themselves do — is to check whether a particular "well known" URI is reachable and has the right content. This not only checks connectivity to the Internet, but is also able to detect whether you are behind some kind of captive portal that requires a login.

For instance, Firefox pokes http://detectportal.firefox.com/canonical.html and checks for a particular string in the returned page. If you were writing a Bash script, you could check the same thing by sticking:

[[ "$(curl --silent --fail --max-time 10 http://detectportal.firefox.com/canonical.html)" == '<meta http-equiv="refresh" content="0;url=https://support.mozilla.org/kb/captive-portal"/>' ]] || exit 1

near the top.

/r/linuxquestions Thread