summaryrefslogtreecommitdiff
path: root/.local/bin/cronic
blob: 8536f29a38cf804e45ae0fa829ff2c0315da9e62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash

# Cronic v2 - cron job report wrapper
# Copyright 2007 Chuck Houpt. No rights reserved, whatsoever.
# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/

set -eu

OUT=/tmp/cronic.out.$$
ERR=/tmp/cronic.err.$$
TRACE=/tmp/cronic.trace.$$

set +e
"$@" >$OUT 2>$TRACE
RESULT=$?
set -e

PATTERN="^${PS4:0:1}\\+${PS4:1}"
if grep -aq "$PATTERN" $TRACE
then
    ! grep -av "$PATTERN" $TRACE > $ERR
else
    ERR=$TRACE
fi

if [ $RESULT -ne 0 -o -s "$ERR" ]
    then
    echo "Cronic detected failure or error output for the command:"
    echo "$@"
    echo
    echo "RESULT CODE: $RESULT"
    echo
    echo "ERROR OUTPUT:"
    cat "$ERR"
    echo
    echo "STANDARD OUTPUT:"
    cat "$OUT"
    if [ $TRACE != $ERR ]
    then
        echo
        echo "TRACE-ERROR OUTPUT:"
        cat "$TRACE"
    fi
fi

rm -f "$OUT"
rm -f "$ERR"
rm -f "$TRACE"