Check HTTP Status Codes with Curl

Learn how to check website HTTP status codes using curl for monitoring and scripting purposes.

Basic Status Code Check

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"

What This Command Does

  • --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

Enhanced Status Check Script

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