Skip to content

Instantly share code, notes, and snippets.

@mars
Created January 3, 2022 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mars/cafb4cfa4962c463b8a7e4f4a4436866 to your computer and use it in GitHub Desktop.
Save mars/cafb4cfa4962c463b8a7e4f4a4436866 to your computer and use it in GitHub Desktop.
Await a URL returning a specific response status, like 200
#!/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