Created
February 17, 2014 08:18
-
-
Save mmaassen/9046744 to your computer and use it in GitHub Desktop.
Script to notify you when a connection restores
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 | |
SLEEP=30 | |
if [[ $# -lt 2 ]]; then | |
echo "Usage: $0 <host> <port>" | |
exit | |
fi | |
TESTHOST=$1 | |
TESTPORT=$2 | |
while true; do | |
echo "--------------------------" | |
echo "Trying: nc -z -w 5 $TESTHOST $TESTPORT" | |
if nc -z -w 5 $TESTHOST $TESTPORT; then | |
date | |
echo "Connection Restored" | |
# say Connection Restored | |
break | |
else | |
date | |
echo -e "\tConnection Failed" | |
fi | |
echo "Waiting $SLEEP seconds ..." | |
sleep $SLEEP | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment