Created
January 3, 2022 22:34
-
-
Save mars/cafb4cfa4962c463b8a7e4f4a4436866 to your computer and use it in GitHub Desktop.
Await a URL returning a specific response status, like 200
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 | |
set -u | |
echo "Checking for response status ${1} from URL: ${2}" | |
try_count=0 | |
while true | |
do | |
((try_count++)) | |
response_status="$(curl -s -o /dev/null -w "%{http_code}" "${2}")" | |
if [ "$response_status" == "${1}" ] | |
then | |
echo "✅ URL is responding to requests" | |
break | |
else | |
if [ $try_count -gt 59 ] | |
then | |
echo "❌ URL is not responding to requests, last status: $response_status" | |
exit 1 | |
else | |
echo "⏳ request failed: $response_status (retry #$try_count in 10-seconds)" | |
sleep 10 | |
continue | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment