Created
February 13, 2020 16:26
-
-
Save taavituisk/cde90ac1cce6143d691a705abacbf02a to your computer and use it in GitHub Desktop.
tcp ping script using netcat
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 | |
pinghost="${1}" | |
pingport="${2}" | |
pingtimeout=10 | |
pingcmd="nc -w ${pingtimeout} ${pinghost} ${pingport}" | |
pingret=0 | |
echo "$(date -Iseconds) - connecting to ${pinghost} ${pingport}" | |
while true; do | |
while [[ ${pingret} = 0 ]]; do | |
pingout="$(${pingcmd} 2>&1)"; pingret=${?} | |
sleep 1 | |
done | |
echo "$(date -Iseconds) - app failure" | |
while [[ ${pingret} != 0 ]]; do | |
pingout="$(${pingcmd} 2>&1)"; pingret=${?} | |
sleep 1 | |
done | |
echo "$(date -Iseconds) - app ok" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment