Last active
November 21, 2016 08:16
-
-
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
This file contains hidden or 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 | |
# 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