Browse Source

Add bin/hterrs HTTP site checker

Alois Mahdal 5 years ago
parent
commit
6e0c8c3d57
2 changed files with 52 additions and 0 deletions
  1. 15
    0
      README.md
  2. 37
    0
      bin/hterrs

+ 15
- 0
README.md View File

@@ -87,6 +87,21 @@ is passed.
87 87
 Use `-l` to list supported TEMPLATEs
88 88
 
89 89
 
90
+### hterrs ###
91
+
92
+    hterrs URL
93
+
94
+Show errors seen when connecting to URL.
95
+
96
+Content is ignored, and instead just errors are printed to stdout so
97
+that they can be used in notifications, etc.  Errors collected include
98
+socket errors, TLS/SSL errors and HTTP errors (eg. 404).
99
+
100
+Exit status is zero if there WERE errors, one if there were none, two
101
+if this script was used incorrectly and three and more in case of other
102
+failure circumstances.
103
+
104
+
90 105
 ### overduer ###
91 106
 
92 107
     overduer [-d] [--] [FILTER]

+ 37
- 0
bin/hterrs View File

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