Skip to content

Instantly share code, notes, and snippets.

@empjustine
Created January 21, 2025 02:43
Show Gist options
  • Save empjustine/def3aa8d84a485e64c016891206da3a6 to your computer and use it in GitHub Desktop.
Save empjustine/def3aa8d84a485e64c016891206da3a6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Cronic v4 - cron job report wrapper
# Copyright 2007-2016 Chuck Houpt. No rights reserved, whatsoever.
# Copyright 2025. 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
env BASH_XTRACEFD=7 SHELLOPTS="xtrace${SHELLOPTS:+:$SHELLOPTS}" "$@" 1>"$OUT" 2>"$ERR" 7>"$TRACE"
RESULT=$?
set -e
if [ $RESULT -ne 0 ] || [ -s "$ERR" ]
then
printf '=== @t> %s $?=%s $@=' "$(date '+%Y-%m-%dT%H:%M:%S%z')" "$RESULT"
printf '%q ' "$@"
printf '\n'
sed -e 's|^|1> |' "$OUT"
sed -e 's|^|2> |' "$ERR"
if [ $RESULT -ne 0 ]
then
sed -e 's|^|7> |' "$TRACE"
fi
printf '=== @t=%s $?=%s $@=' "$(date '+%Y-%m-%dT%H:%M:%S%z')" "$RESULT"
printf '%q ' "$@"
printf '\n'
fi
rm -rf "$TMP"
exit $RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment