Skip to content

Instantly share code, notes, and snippets.

@lonelyelk
Last active March 30, 2016 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonelyelk/64768e88c2fd02992aade0838f4e235f to your computer and use it in GitHub Desktop.
Save lonelyelk/64768e88c2fd02992aade0838f4e235f to your computer and use it in GitHub Desktop.
Fast and furious ping routine to detect if Internet is accessible or a computer is online.
#!/bin/bash
cnt=${2:-3}
to=${3:-1}
rcvd=$(set -o pipefail; timeout $to ping -A -s16 -c$cnt -q $1 2> /dev/null | grep received | awk -F', ' '{print $2}' | awk '{print $1}')
if [[ $? != 0 || $cnt != $rcvd ]]; then
exit 1
fi
@lonelyelk
Copy link
Author

Usage:

./fastping.sh HOST [COUNT=3 [TIMEOUT=1]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment