Check HTTP Status Codes with Curl
Learn how to check website HTTP status codes using curl for monitoring and scripting purposes.
Use curl to quickly check if a website is responding with a successful HTTP status code:
curl \
--output /dev/null \
--silent \
--write-out "%{http_code}" \
"https://decaf200.com"
--output /dev/null: Discards the response body (we only want the status code)--silent: Suppresses progress meter and error messages--write-out "%{http_code}": Outputs only the HTTP status code- The URL in quotes to handle special characters
For more robust monitoring, you can create a script that handles different scenarios:
#!/usr/bin/env bash
set -euo pipefail
url="https://decaf200.com"
status_code=$(curl --output /dev/null --silent --write-out "%{http_code}" "$url")
if [[ "$status_code" -eq 200 ]]; then
echo "â
Site is up (HTTP $status_code)"
elif [[ "$status_code" -ge 400 ]]; then
echo "â Site has issues (HTTP $status_code)"
else
echo "âšī¸ Site returned (HTTP $status_code)"
fi