Simple HTTP Status Monitor Using Curl


Using some output redirection and the --write-out parameter we can produce a script that simply outputs the status code of a curl request.

This script can then be used as the basis for a simple monitoring of a URL.

#! /bin/bash
# Description: Returns the HTTP response code obtained by curl on the URL using the specified HTTP method
# Usage: script.sh GET https://example.org
# Usage: scripts.sh POST https://example.org
# Author: marco@kamner.eu

METHOD=$1
URL=$2

curl --silent --output /dev/null --write-out "%{http_code}" --request $METHOD $URL

This script can easily be adapted to output other information using the variables available to --write-out.

See also