WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script http-health-check

HTTP Health Check

Check URLs for expected status codes and response time.

category Networking shell Bash 4+ updated 2026-09-01
httpcurlmonitoringnetwork
Safety notes
  • Sends requests to the listed URLs. Do not point it at endpoints with side effects.

Dependencies: curl

Usage

  • Pass one or more URLs.
  • Set EXPECT to the required status code (default 200).

Script

#!/usr/bin/env bash
set -euo pipefail

expect="${EXPECT:-200}"
(($# > 0)) || { echo "usage: $0 URL [URL...]" >&2; exit 1; }
fail=0

for url in "$@"; do
  read -r code seconds < <(
    curl -sS -o /dev/null -w '%{http_code} %{time_total}\n' \
      --max-time 10 --retry 1 "$url" || echo "000 0"
  )
  if [[ "$code" == "$expect" ]]; then
    printf 'ok    %s  %ss  %s\n' "$code" "$seconds" "$url"
  else
    printf 'fail  %s  %ss  %s\n' "$code" "$seconds" "$url" >&2
    fail=1
  fi
done

exit "$fail"

Example

./http-health-check https://example.com https://example.com/health
EXPECT=204 ./http-health-check https://api.example.com/ping

Notes

  • 000 means curl could not complete the request — DNS, TLS, or timeout.
  • For authenticated endpoints, pass headers via a curl config file rather than hardcoding tokens here.

Related scripts

Service Health Check

Check systemd services and HTTP endpoints in one pass with a non-zero exit on failure.

Monitoring

Disk Threshold Alert

Exit non-zero when any mounted filesystem exceeds a usage threshold.

Monitoring