From 03b195c0851d94baeb0ce5348fe97c6c42e464a7 Mon Sep 17 00:00:00 2001 From: Sven Dahlstrand Date: Tue, 31 Jan 2017 07:38:43 +0100 Subject: [PATCH] Add script to check HTTP status for URLs. --- scripts/urls-http-status | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 scripts/urls-http-status diff --git a/scripts/urls-http-status b/scripts/urls-http-status new file mode 100755 index 0000000..04704d9 --- /dev/null +++ b/scripts/urls-http-status @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# +# Find URLs in ../README.md and print them with their HTTP status code. +# +# Example usage: +# +# $ ./scripts/urls-http-status | sort +# 200 http://example.com/page.html +# 200 http://example.com/another-page.html +# [...] +# 404 http://example.com/missing-page.html +# +# Changing the number of parallel processes is possible. The default is 10. +# +# $ MAX_PARALLEL=100 ./scripts/urls-http-status + +MAX_PARALLEL=${MAX_PARALLEL:-10} +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +grep -Eoie "\(https?://.*?\)" "$DIR/../README.md" |\ + cut -d "(" -f 2 |\ + cut -d ")" -f 1 |\ + xargs -n1 -P "$MAX_PARALLEL" curl -o /dev/null --silent --head --write-out "%{http_code} %{url_effective}\n"