comparison bin/cronic @ 492:0c2d6458248e

Add cronic.
author edogawaconan <me@myconan.net>
date Fri, 08 Nov 2013 17:56:37 +0900
parents
children 8fa04c2a9896
comparison
equal deleted inserted replaced
491:c3c2353044ad 492:0c2d6458248e
1 #!/usr/bin/env bash
2
3 # Mod by edogawaconan:
4 # - `/usr/bin/env bash`
5 # Source: http://habilis.net/cronic/
6 #
7 # Cronic v2 - cron job report wrapper
8 # Copyright 2007 Chuck Houpt. No rights reserved, whatsoever.
9 # Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
10
11 set -eu
12
13 OUT=/tmp/cronic.out.$$
14 ERR=/tmp/cronic.err.$$
15 TRACE=/tmp/cronic.trace.$$
16
17 set +e
18 "$@" >$OUT 2>$TRACE
19 RESULT=$?
20 set -e
21
22 PATTERN="^${PS4:0:1}\\+${PS4:1}"
23 if grep -aq "$PATTERN" $TRACE
24 then
25 ! grep -av "$PATTERN" $TRACE > $ERR
26 else
27 ERR=$TRACE
28 fi
29
30 if [ $RESULT -ne 0 -o -s "$ERR" ]
31 then
32 echo "Cronic detected failure or error output for the command:"
33 echo "$@"
34 echo
35 echo "RESULT CODE: $RESULT"
36 echo
37 echo "ERROR OUTPUT:"
38 cat "$ERR"
39 echo
40 echo "STANDARD OUTPUT:"
41 cat "$OUT"
42 if [ $TRACE != $ERR ]
43 then
44 echo
45 echo "TRACE-ERROR OUTPUT:"
46 cat "$TRACE"
47 fi
48 fi
49
50 rm -f "$OUT"
51 rm -f "$ERR"
52 rm -f "$TRACE"