script bash waiting for http server

script bash waiting for http server

How-To

Waiting for http server responding on http://localhost:8080

while [ "$(HEAD http://localhost:8080 | grep '200\ OK' | wc -l)" = "0" ]; do echo -n "."; sleep 1; done;

Explanation:

While http server is not ready, HEAD receives http code 500 with conection refused error

HEAD http://localhost:8080
500 Can't connect to localhost:8080 (Connection refused)
Content-Type: text/plain
Client-Date: Fri, 05 Apr 2019 07:11:06 GMT
Client-Warning: Internal response

When the server is ready, HEAD receives http code 200 (OK)

HEAD http://localhost:8080
200 OK
Cache-Control: no-cache, must-revalidate, max-age=0
Connection: close
Date: Fri, 05 Apr 2019 07:09:47 GMT
Server: Apache/2.4.25 (Debian)
...etc
admin

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax