#!/bin/bash
# HTTP check of migrated sites through nginx on this server. usage: http-check.sh <ip> [user:pass]
IP=$1; AUTH=${2:-}
A=(); [ -n "$AUTH" ] && A=(-u "$AUTH")
chk() { # url
  local h; h=$(echo "$1" | sed -E 's#https?://([^/]+).*#\1#')
  curl -sk -o /tmp/hc.body -w '%{http_code} %{size_download}B %{time_total}s' "${A[@]}" --resolve "$h:443:$IP" --resolve "$h:80:$IP" "$1"
  printf ' | title %s | php-err %s\n' "$(grep -o '<title>' /tmp/hc.body | head -1 | wc -l | tr -d ' ')" "$(grep -cE 'Fatal error|Parse error|SqlQueryException|Warning</b>:' /tmp/hc.body)"
}
while read -r u; do [ -n "$u" ] && printf '%-60s ' "$u" && chk "$u"; done
rm -f /tmp/hc.body
