0

Being a noob, I can't comment, so posting a question to expand on the answers for this thread; How to test an Internet connection with bash?

for Mac users.

The -w1 or -w 1 option specified in the answers does not work on Mac However, -W1 or -W 1 does work. It is a case sensitivity issue for the Mac rather than an invalid/unavailable option.

jphale
  • 3
  • 2

1 Answers1

0

On Mac: I assume you need a timeout? What's wrong with using the -t option (timeout) ?

A script for this, adapted from your link:

checkInternet () {
    error=$(ping -q  -t1 -c1 "8.8.8.8" 2>&1 >"/dev/null" || true)

    if [ "${error}" != "" ]; then
        echo "No internet" >&2
        exit 1
    fi
    echo "Internet" >&2
}

checkInternet
agentsmith
  • 1,226
  • 1
  • 14
  • 27
  • Nice Idea! Using the info from the link I had put this together to check connectivity in the local system ``` if ping -q -W 1 -c 1 $1> /dev/null; then echo "$1 connected" else echo "$1 offline" fi ``` – jphale Oct 20 '19 at 23:56