]>
git.sthu.org Git - shutils.git/blob - ifonline
7 Executes a given command if there is an internet connection. Availability of an
8 connection is tested by (i) the availability of a default route and (ii) the
9 pingability of a test host.
19 -p HOST Host for ping test. Default: 8.8.8.8
20 -c CMD Command to execute if online
28 while getopts "hvc:p:" OPTION
; do
47 if [ -z "${CMD}" ]; then
48 echo "No command given."
53 if [ -z "$(ip r list exact default)" ]; then
54 if [ "1" -eq "${VERBOSE}" ]; then
55 echo "Not online because no default route."
61 if ! ping -c1 "${PINGHOST}" 2>&1 >/dev
/null
; then
62 if [ "1" -eq "${VERBOSE}" ]; then
63 echo "Not online because cannot ping ${PINGHOST}."