Skip to content

Instantly share code, notes, and snippets.

@stfwn
Created January 19, 2021 09:37
Show Gist options
  • Save stfwn/ddeb79a912b701d657b08783c16fdc41 to your computer and use it in GitHub Desktop.
Save stfwn/ddeb79a912b701d657b08783c16fdc41 to your computer and use it in GitHub Desktop.
Find dead links in your ReStructuredText files
#!/bin/bash
# This script grabs ReStructuredText-style hyperlinks in all rst files from cwd down,
# then prints a list of status codes for a GET request to each of them. It's useful
# for finding dead links.
# This will match:
# - "<www.example.com>"
# - "<https://www.example.com"
# - "<https://example.com"
#
# This will not match:
# - "<example.com>"
# - "www.example.com"
# - "https://example.com"
echo "Response Code URL"
grep --extended-regexp\
--recursive\
--only-matching\
--no-filename\
--include="*.rst"\
"<((https://)|(www)).*>"\
| sed "s/[<>]//g"\
| xargs -n 1 curl -sL -o /dev/null -w '%{response_code}\t\t%{url_effective}\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment