Created
March 4, 2011 07:31
-
-
Save joshenders/854307 to your computer and use it in GitHub Desktop.
Silly little script to detect when WWAN is being flakey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# WWAN can be flakey. This script pings your ISP's gateway. After 5 missed | |
# responses, this script produces an audible bell until the host starts | |
# responding again. | |
if [[ "$#" -ne '0' ]]; then | |
echo "Usage: $0" >&2 | |
exit 1 | |
fi | |
threshold=5 | |
# second hop should be ISP gateway assuming a NAT'd host | |
host=$(traceroute -nm2 8.8.8.8 2>&1 | tail -n 1 | awk '{ print $2 }') | |
while true; do | |
# quiet timeout count packetsize | |
status=$(ping -q -t1 -c1 -s0 $host >/dev/null 2>&1; echo $?) | |
if [[ "$status" -gt '0' ]]; then | |
echo -ne 'x' | |
miss=$(($miss+1)) | |
if [[ "$miss" -gt "$(($threshold - 1))" ]]; then | |
echo -ne "\a" | |
fi | |
else | |
echo -n '.' | |
miss=0 | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment