diff options
| author | Scott Ostler <scottbot9000@gmail.com> | 2010-11-07 14:27:09 -0500 |
|---|---|---|
| committer | Scott Ostler <scottbot9000@gmail.com> | 2010-11-07 14:27:09 -0500 |
| commit | d431c6ea21e5071521b04c439770935cafe25184 (patch) | |
| tree | c5b2c92eea4a5fd2c8c0ad29f380408df03a9ae9 /scripts | |
| parent | f9440deeb6dac3310efa8b1c9322885eea5b4ddf (diff) | |
| parent | f5692dcbff94853078cb06ea63c881bb0588e297 (diff) | |
Merge branch 'master' of ssh://dump.fm/pichat/repo
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/cronic | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/cronic b/scripts/cronic new file mode 100755 index 0000000..80f1cad --- /dev/null +++ b/scripts/cronic @@ -0,0 +1,54 @@ +#!/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.$$ +LOGDIR=/var/log/cronic + +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 + +# sbostler: write log for all job runs +SCRIPT=$(basename $1) +OUTLOG=$(date +"$LOGDIR/$SCRIPT.%Y-%m-%d__%T.log") +cat "$OUT" > $OUTLOG + +rm -f "$OUT" +rm -f "$ERR" +rm -f "$TRACE" |
