Przeglądaj źródła

Add bin/hterrs HTTP site checker

Alois Mahdal 6 lat temu
rodzic
commit
6e0c8c3d57
2 zmienionych plików z 52 dodań i 0 usunięć
  1. 15
    0
      README.md
  2. 37
    0
      bin/hterrs

+ 15
- 0
README.md Wyświetl plik

@@ -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 Wyświetl plik

@@ -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 "$@"