I use this command to print the status code without any other output. Additionally, it will only perform a HEAD request and follow the redirection (respectively -I
and -L
).
curl -o -I -L -s -w "%{http_code}" http://localhost
This makes it very easy to check the status code in a health script:
sh -c '[ $(curl -o -I -L -s -w "%{http_code}" http://localhost) -eq 200 ]'