Skip to content

Instantly share code, notes, and snippets.

@pkoch
Created April 17, 2020 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pkoch/3619659c2e9c5a3e8fb7b81bc5f15eec to your computer and use it in GitHub Desktop.
Save pkoch/3619659c2e9c5a3e8fb7b81bc5f15eec to your computer and use it in GitHub Desktop.
#!/bin/bash
# pkoch: I've removed the trace funcionality, unified outputs, and only send email on non-zero result.
# 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
set +e
"$@" >$OUT 2>&1
RESULT=$?
set -e
if [ $RESULT -ne 0 ]; then
echo "Cronic detected failure or error output for the command:"
echo "$@"
echo
echo "RESULT CODE: $RESULT"
echo
echo "OUTPUT:"
cat "$OUT"
fi
rm -rf "$TMP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment