annotate bin/cronic @ 657:91d7c2e5936c

Remove need to manually switch directory with sud
author nanaya <me@nanaya.pro>
date Sun, 25 Jul 2021 21:36:52 +0900
parents 0c2d6458248e
children 8fa04c2a9896
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 #
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
7 # Cronic v2 - cron job report wrapper
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
8 # Copyright 2007 Chuck Houpt. No rights reserved, whatsoever.
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
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
13 OUT=/tmp/cronic.out.$$
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
14 ERR=/tmp/cronic.err.$$
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
15 TRACE=/tmp/cronic.trace.$$
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
16
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
17 set +e
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
18 "$@" >$OUT 2>$TRACE
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
19 RESULT=$?
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
20 set -e
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
21
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
22 PATTERN="^${PS4:0:1}\\+${PS4:1}"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
23 if grep -aq "$PATTERN" $TRACE
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
24 then
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
25 ! grep -av "$PATTERN" $TRACE > $ERR
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
26 else
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
27 ERR=$TRACE
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
28 fi
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
29
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
30 if [ $RESULT -ne 0 -o -s "$ERR" ]
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
31 then
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
32 echo "Cronic detected failure or error output for the command:"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
33 echo "$@"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
34 echo
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
35 echo "RESULT CODE: $RESULT"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
36 echo
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
37 echo "ERROR OUTPUT:"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
38 cat "$ERR"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
39 echo
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
40 echo "STANDARD OUTPUT:"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
41 cat "$OUT"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
42 if [ $TRACE != $ERR ]
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
43 then
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
44 echo
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
45 echo "TRACE-ERROR OUTPUT:"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
46 cat "$TRACE"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
47 fi
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
48 fi
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
49
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
50 rm -f "$OUT"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
51 rm -f "$ERR"
0c2d6458248e Add cronic.
edogawaconan <me@myconan.net>
parents:
diff changeset
52 rm -f "$TRACE"