Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner

lonelyelk commented Mar 30, 2016

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