Skip to content

Instantly share code, notes, and snippets.

@dtelaroli
Forked from rgl/wait_for_http_200.sh
Last active January 11, 2019 14:00
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 dtelaroli/c6aa76033a0d2ab0c001951846200519 to your computer and use it in GitHub Desktop.
Save dtelaroli/c6aa76033a0d2ab0c001951846200519 to your computer and use it in GitHub Desktop.
Wait for an HTTP endpoint to return 200 OK with Bash and curl
#!/bin/bash
# Usage
# $ chmod +x ./wait_for_http_200.sh
# $ sh wait_for_http_200.sh http://<host>:<port>/<path>
echo "Trying to reach ${1}"
i=0
while [[ "$(curl -s -o /dev/null -w '%{http_code}' ${1})" != "200" ]]; do
sleep 5
let "i+=5"
echo "Trying again after ${i} seconds. Press Ctrl + C to cancel."
done
echo 'Service OK'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment