annotate bin/cronic @ 693:37a2470380f2

[bashrc] Fix comment about freebsd grep
author nanaya <me@nanaya.pro>
date Sun, 23 Oct 2022 01:56:54 +0900
parents 8fa04c2a9896
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
492
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
1 #!/usr/bin/env bash
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
2
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
3 # Mod by edogawaconan:
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
4 # - `/usr/bin/env bash`
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
5 # Source: http://habilis.net/cronic/
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
6 #
679
8fa04c2a9896 [cronic] update
nanaya <me@nanaya.pro>
parents: 492
diff changeset
7 # Cronic v3 - cron job report wrapper
8fa04c2a9896 [cronic] update
nanaya <me@nanaya.pro>
parents: 492
diff changeset
8 # Copyright 2007-2016 Chuck Houpt. No rights reserved, whatsoever.
492
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
9 # Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
10
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
11 set -eu
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
12
679
8fa04c2a9896 [cronic] update
nanaya <me@nanaya.pro>
parents: 492
diff changeset
13 TMP=$(mktemp -d)
8fa04c2a9896 [cronic] update
nanaya <me@nanaya.pro>
parents: 492
diff changeset
14 OUT=$TMP/cronic.out
8fa04c2a9896 [cronic] update
nanaya <me@nanaya.pro>
parents: 492
diff changeset
15 ERR=$TMP/cronic.err
8fa04c2a9896 [cronic] update
nanaya <me@nanaya.pro>
parents: 492
diff changeset
16 TRACE=$TMP/cronic.trace
492
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
17
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
18 set +e
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
19 "$@" >$OUT 2>$TRACE
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
20 RESULT=$?
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
21 set -e
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
22
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
23 PATTERN="^${PS4:0:1}\\+${PS4:1}"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
24 if grep -aq "$PATTERN" $TRACE
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
25 then
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
26 ! grep -av "$PATTERN" $TRACE > $ERR
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
27 else
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
28 ERR=$TRACE
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
29 fi
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
30
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
31 if [ $RESULT -ne 0 -o -s "$ERR" ]
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
32 then
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
33 echo "Cronic detected failure or error output for the command:"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
34 echo "$@"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
35 echo
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
36 echo "RESULT CODE: $RESULT"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
37 echo
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
38 echo "ERROR OUTPUT:"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
39 cat "$ERR"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
40 echo
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
41 echo "STANDARD OUTPUT:"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
42 cat "$OUT"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
43 if [ $TRACE != $ERR ]
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
44 then
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
45 echo
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
46 echo "TRACE-ERROR OUTPUT:"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
47 cat "$TRACE"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
48 fi
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
49 fi
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
50
679
8fa04c2a9896 [cronic] update
nanaya <me@nanaya.pro>
parents: 492
diff changeset
51 rm -rf "$TMP"