From f5692dcbff94853078cb06ea63c881bb0588e297 Mon Sep 17 00:00:00 2001 From: dumpfmprod Date: Sun, 7 Nov 2010 12:08:45 -0500 Subject: Added cronic script w/ logging modifications --- scripts/cronic | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 scripts/cronic (limited to 'scripts') 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" -- cgit v1.2.3-70-g09d2