Skip to content

Instantly share code, notes, and snippets.

@fgimian
Last active November 21, 2016 08:16
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 fgimian/c07ae1c2539f7282cf2dc42e692f6718 to your computer and use it in GitHub Desktop.
Save fgimian/c07ae1c2539f7282cf2dc42e692f6718 to your computer and use it in GitHub Desktop.
A simple little script to run on macOS to test stability of your internet connection
#!/bin/bash
# Set the destination IP or hostname to ping
DESTINATION=8.8.8.9
# Ping the endpoint and write an error to a log file if the ping fails 5 times consecutively
FAILURE_COUNT=0
while true
do
ping -c 1 -t 1 $DESTINATION > /dev/null 2>&1
[ $? -eq 0 ] && FAILURE_COUNT=0 || FAILURE_COUNT=$((FAILURE_COUNT + 1))
if [ $FAILURE_COUNT -eq 5 ]
then
DATESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
echo "${DATESTAMP} Unable to ping ${DESTINATION}" >> "${HOME}/test_ping.log"
FAILURE_COUNT=0
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment