12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. #shellcheck disable=SC1090
  3. . "$(sfpath)" || exit 3
  4. shellfu import pretty
  5. PRETTY_DEBUG=${PRETTY_DEBUG:-true}
  6. usage() {
  7. mkusage "$@" "URL" \
  8. -- \
  9. "Show errors seen when connecting to URL." \
  10. "" \
  11. "Content is ignored, and instead just errors are printed to stdout" \
  12. "so that they can be used in notifications, etc. Errors collected" \
  13. "include socket errors, TLS/SSL errors and HTTP errors (eg. 404)." \
  14. "" \
  15. "Exit status is zero if there WERE errors, one if there were none," \
  16. "two if this script was used incorrectly and three and more in case"\
  17. "of other failure circumstances."
  18. }
  19. main() {
  20. local HtUrl
  21. while true; do case $1 in
  22. -*) usage -w "unknown argument: $1" ;;
  23. *) break ;;
  24. esac done
  25. HtUrl=$1
  26. test -n "$HtUrl" || usage -w "no URL?"
  27. curl -fLs "$HtUrl" >/dev/null \
  28. || echo "URL failed, error status: $?" \
  29. || grep .
  30. }
  31. main "$@"