Skip to content

Instantly share code, notes, and snippets.

@taavituisk
Created February 13, 2020 16:26
Show Gist options
  • Save taavituisk/cde90ac1cce6143d691a705abacbf02a to your computer and use it in GitHub Desktop.
Save taavituisk/cde90ac1cce6143d691a705abacbf02a to your computer and use it in GitHub Desktop.
tcp ping script using netcat
#!/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