brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl -w prints the status code and timing and nothing else

Curl
~/tips/tip-linux-curl-write-out

curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://example.com

Prints only the HTTP status code and response time of a URL.

I do not always want a page. Sometimes I only want to know whether a URL answers and how fast.

Throw the body away and print what you care about:

curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://example.com

-o /dev/null discards the body, -s hides the progress meter, -S still shows real errors, and -w prints a format string after the transfer. The output is something like 200 0.123s. Other variables worth knowing are %{time_connect}, %{size_download} and %{redirect_url}.

The caveat: curl does not follow redirects unless you add -L, so a site that redirects shows a 301 and the time of the first hop only. The time also includes DNS lookup, so compare the same command twice before you blame the server.

I find this a quick way to build a tiny uptime check in a shell script. Put the status code in a variable and compare it with 200, and you have a health check without installing anything. For a one-off look at response headers instead, curl -I is the shortcut, though some servers answer HEAD differently from GET.

Further reading: curl man page: –write-out, curl: write-out variables, On this site: curl -I shows the HTTP headers of a page without downloading it

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link