# Created on savesnippets.com ยท https://savesnippets.com/LjK9RX1Mi5nHIJ check_url() { local url="$1" expected="${2:-200}" local code code="$(curl -sS -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 10 "$url")" if [[ "$code" == "$expected" ]]; then return 0 else echo "FAIL $url got $code (expected $expected)" >&2 return 1 fi } check_url https://savesnippets.com && echo "homepage OK" check_url https://savesnippets.com/login.php && echo "login OK" # Wait until a service comes up (handy in docker-compose start scripts) wait_for_url() { local url="$1" timeout="${2:-60}" local start; start=$(date +%s) until check_url "$url" 2>/dev/null; do if (( $(date +%s) - start > timeout )); then echo "$url never came up in $timeout s" >&2; return 1 fi sleep 1 done }