Skip to content

Instantly share code, notes, and snippets.

@mmaassen
Created February 17, 2014 08:18
Show Gist options
  • Save mmaassen/9046744 to your computer and use it in GitHub Desktop.
Save mmaassen/9046744 to your computer and use it in GitHub Desktop.
Script to notify you when a connection restores
#!/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