aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/broken-links
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/broken-links')
-rwxr-xr-x.local/bin/broken-links34
1 files changed, 32 insertions, 2 deletions
diff --git a/.local/bin/broken-links b/.local/bin/broken-links
index 843f0ff..02db6a0 100755
--- a/.local/bin/broken-links
+++ b/.local/bin/broken-links
@@ -1,3 +1,33 @@
#!/bin/sh -eu
-wget --spider --recursive --level 3 --no-verbose \
- --no-directories --delete-after "$1" 2>&1 | grep -v -E 'URL:|unlink:'
+
+lynx \
+ -nocolor \
+ -dump \
+ -listonly \
+ "${1:-https://example.com}" |
+ grep \
+ --color="never" \
+ "\." |
+ while read -r line; do
+ url=${line#*. }
+ head=$(wget \
+ --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36" \
+ --timeout=1 \
+ --wait=1 \
+ --waitretry=1 \
+ --random-wait \
+ --no-cache \
+ --no-dns-cache \
+ --method=HEAD "$url" 2>&1 |
+ grep --color="never" -E 'HTTP')
+ response=$(printf '%s' "${head#*... }" | head --lines=1)
+ printf '%s %s\n' "$url" "$response"
+ printf '%s %s\n' "$url" "$response" >&2
+ done |
+ awk '{ print $1, $2, $3}' |
+ column \
+ --output-width 80 \
+ --table \
+ --table-columns URL,STATUS,MESSAGE \
+ --table-truncate URL |
+ sort --reverse --key=2