~kris/dots

srice

ref: 178c9a25a484ead715392d50e21d03df486b8b41 srice/.local/bin/blog-linkrot -rwxr-xr-x 551 bytes
178c9a25 — Kris Yotam conky: sync proper config from moirai (was the greenred variant) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env sh
set -eu

blog-links "$@" | cut -f1 | sort -u |
while IFS= read -r url; do
  [ -n "$url" ] || continue
  code=$(curl -LIs --max-time 15 --user-agent 'blog-linkrot/1.0' "$url" 2>/dev/null | awk '/^HTTP/{c=$2} END{print c}')
  if [ -z "$code" ] || [ "$code" = "405" ]; then
    code=$(curl -Ls -o /dev/null -w '%{http_code}' --max-time 20 --user-agent 'blog-linkrot/1.0' "$url" 2>/dev/null || true)
  fi
  case "$code" in
    2*|3*) printf 'ok %s %s\n' "$code" "$url" ;;
    *) printf 'bad %s %s\n' "${code:-000}" "$url" ;;
  esac
done