2016-05-14 13:49:52 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Cronic v3 - cron job report wrapper
|
|
|
|
# Copyright 2007-2016 Chuck Houpt. No rights reserved, whatsoever.
|
|
|
|
# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
TMP=$(mktemp -d)
|
|
|
|
OUT=$TMP/cronic.out
|
|
|
|
ERR=$TMP/cronic.err
|
|
|
|
TRACE=$TMP/cronic.trace
|
|
|
|
|
|
|
|
set +e
|
2018-02-26 14:50:40 +01:00
|
|
|
"$@" >"$OUT" 2>"$TRACE"
|
2016-05-14 13:49:52 +02:00
|
|
|
RESULT=$?
|
|
|
|
set -e
|
|
|
|
|
|
|
|
PATTERN="^${PS4:0:1}\\+${PS4:1}"
|
2018-02-26 14:50:40 +01:00
|
|
|
if grep -aq "$PATTERN" "$TRACE"
|
2016-05-14 13:49:52 +02:00
|
|
|
then
|
2018-02-26 14:50:40 +01:00
|
|
|
! grep -av "$PATTERN" "$TRACE" > "$ERR"
|
2016-05-14 13:49:52 +02:00
|
|
|
else
|
|
|
|
ERR=$TRACE
|
|
|
|
fi
|
|
|
|
|
2016-05-14 14:36:19 +02:00
|
|
|
if [ $RESULT -ne 0 ]
|
2016-05-14 13:49:52 +02:00
|
|
|
then
|
|
|
|
echo "Cronic detected failure or error output for the command:"
|
|
|
|
echo "$@"
|
|
|
|
echo
|
|
|
|
echo "RESULT CODE: $RESULT"
|
|
|
|
echo
|
|
|
|
echo "STANDARD OUTPUT:"
|
|
|
|
cat "$OUT"
|
2018-02-26 14:50:40 +01:00
|
|
|
if [ "$TRACE" != "$ERR" ]
|
2016-05-14 13:49:52 +02:00
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "TRACE-ERROR OUTPUT:"
|
|
|
|
cat "$TRACE"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf "$TMP"
|