mamweb/checklinks.sh

19 lines
548 B
Bash
Raw Normal View History

2021-09-03 02:54:15 +02:00
#!/bin/sh
# Props to https://www.commandlinefu.com/commands/view/8234/check-broken-links-using-wget-as-a-spider
set -eu
if test "$#" -lt 1; then
echo >&2 "Usage: $0 <wget parameters, especially URL to test>"
exit 1
fi
2021-09-03 02:58:41 +02:00
logfile="$(pwd)/wget.log.$(date +%FT%T)"
2021-09-03 02:54:15 +02:00
tmp=$(mktemp --directory)
cd "$tmp"
wget --spider -o "$logfile" -r -p -X '/soustredeni/*/fotogalerie/' "$@" || true # wget nejspíš skončí s chybou, že něco nestáhl…
echo "Result: (a last few lines of the file $logfile)"
sed -ne '/^Found [0-9]* broken link/,$ p' "$logfile"