-
-
Save p0z/3894d69f90141a463f790db6da8f6547 to your computer and use it in GitHub Desktop.
Wait for HTTP endpoints to return 200 OK with bash, curl and timeout
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 | |
############################################################################################## | |
# Wait for URLs until return HTTP 200 | |
# | |
# - Just pass as many urls as required to the script - the script will wait for each, one by one | |
# | |
# Example: ./wait_for_urls.sh "${MY_VARIABLE}" "http://192.168.56.101:8080" | |
############################################################################################## | |
wait-for-url() { | |
echo -n "Waiting $1 " | |
timeout --foreground -s TERM 10s bash -c \ | |
'while [[ "$(curl -k -s -o /dev/null -m 3 -L -w ''%{http_code}'' ${0})" != "200" ]];\ | |
do | |
echo -n "." | |
sleep 1 | |
done' ${1} | |
TIMEOUT_RETURN="$?" | |
if [[ "$TIMEOUT_RETURN" == 0 ]]; then | |
echo -e "\n[+] ${1} - 200 OK" | |
else | |
echo -e "\n[-] ${1} - timeout or other error! [$TIMEOUT_RETURN]" | |
fi | |
} | |
clear | |
echo -e "URLs: $@\n" | |
for var in "$@"; do | |
wait-for-url "$var" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment