Last active
October 14, 2022 20:33
-
-
Save hebertluiz/55d40a8d44fa09142698797f3f37d727 to your computer and use it in GitHub Desktop.
Wait for host up before doing stuff Shellscript | Linux
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
target_host='google.com' | |
interval=2 | |
printf '\nWaiting for host %s' "${target_host}" | |
while true; do | |
if ping -c 2 -i .1 -W .5 ${target_host} > /dev/null; then | |
printf '\rHost is %s up. Time to continue' "${target_host}" | |
break | |
fi | |
## time to wait | |
sleep ${interval:-2} | |
printf '\rWaiting for host %s' "${target_host}" | |
done | |
### Do stuff here |
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
# DST_PORT=443 | |
# DST_PROTO='https' | |
http_response_ok='200' | |
target_host='google.com' | |
interval=2 | |
printf '\nWaiting for host %s' "${target_host}" | |
while true; do | |
curl_ret="$(curl -k -o -I -L -s -w "%{http_code}" ${DST_PROTO:-http}://localhost:${DST_PORT:-80})" | |
if [ ${curl_ret} -eq ${http_response_ok:-200} ] ; then | |
printf '\rHost is %s up. Time to continue\n' "${target_host}" | |
break | |
fi | |
## time to wait | |
sleep ${interval:-2} | |
printf '\rWaiting for host %s' "${target_host}" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment