1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. # Cronic v3 - cron job report wrapper
  3. # Copyright 2007-2016 Chuck Houpt. No rights reserved, whatsoever.
  4. # Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
  5. set -eu
  6. TMP=$(mktemp -d)
  7. OUT=$TMP/cronic.out
  8. ERR=$TMP/cronic.err
  9. TRACE=$TMP/cronic.trace
  10. set +e
  11. "$@" >$OUT 2>$TRACE
  12. RESULT=$?
  13. set -e
  14. PATTERN="^${PS4:0:1}\\+${PS4:1}"
  15. if grep -aq "$PATTERN" $TRACE
  16. then
  17. ! grep -av "$PATTERN" $TRACE > $ERR
  18. else
  19. ERR=$TRACE
  20. fi
  21. if [ $RESULT -ne 0 ]
  22. then
  23. echo "Cronic detected failure or error output for the command:"
  24. echo "$@"
  25. echo
  26. echo "RESULT CODE: $RESULT"
  27. echo
  28. echo "STANDARD OUTPUT:"
  29. cat "$OUT"
  30. if [ $TRACE != $ERR ]
  31. then
  32. echo
  33. echo "TRACE-ERROR OUTPUT:"
  34. cat "$TRACE"
  35. fi
  36. fi
  37. rm -rf "$TMP"