Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wait for an HTTP endpoint to return 200 OK with Bash and curl
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9000)" != "200" ]]; do sleep 5; done'
# also check https://gist.github.com/rgl/c2ba64b7e2a5a04d1eb65983995dce76
@wilk

This comment has been minimized.

Copy link

wilk commented Mar 14, 2019

timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9000)" != "200" ]]; do sleep 5; done' || false

version with 5 minutes of timeout: if timeout is reached, it exits with error (1)

@neonidian

This comment has been minimized.

Copy link

neonidian commented May 10, 2019

For TLS add --insecure flag for self signed certificates
timeout 300 bash -c 'while [[ "$(curl --insecure -s -o /dev/null -w ''%{http_code}'' https://localhost:9000)" != "200" ]]; do sleep 5; done'

@bukowa

This comment has been minimized.

Copy link

bukowa commented Jan 21, 2020

How to print status code before sleep?

@aaronArinder

This comment has been minimized.

Copy link

aaronArinder commented Jan 24, 2020

This is awesome--thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.