This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcronic
executable file
·86 lines (73 loc) · 2.08 KB
/
cronic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# based on Cronic v2 - cron job report wrapper downloaded from http://habilis.net/cronic/cronic
# Copyright 2007 Chuck Houpt
# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
# modified by BCT 2008 to use voro logging scheme, tweaked in 2013 for appstrap
if [[ -n "$DEBUG" ]]; then
set -x
fi
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset ## set -u : exit the script if you try to use an uninitialised variable
set -o errexit ## set -e : exit the script if any statement returns a non-true return value
logname=$(basename "$1")
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # http://stackoverflow.com/questions/59895
LOGDIR=$DIR/log
mkdir -p "$LOGDIR"
OUT=$LOGDIR/${logname}.$TIMESTAMP.out
ERR=$LOGDIR/${logname}.$TIMESTAMP.err
TRACE=$LOGDIR/${logname}.$TIMESTAMP.trc
ionice -c3 -p$$
renice -n 10 $$ > /dev/null
PATH=$HOME/pdfu/ve/bin:$PATH:$HOME/.local/bin:$HOME/bin
export PATH
# run command
set +e
"$@" >"$OUT" 2>"$TRACE"
RESULT=$?
set -e
if [ -e /usr/xpg4/bin/grep ]; then # solaris
GREP=/usr/xpg4/bin/grep
elif [ -e /bin/grep ]; then # Amazon Linux AMI
GREP=/bin/grep
else
GREP=/usr/bin/grep
fi
PATTERN="^${PS4:0:1}\\+${PS4:1}"
if $GREP -q "$PATTERN" "$TRACE"
then
! $GREP -v "$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: tail $ERR"
tail "$ERR"
echo
echo "STANDARD OUTPUT: tail $OUT"
tail "$OUT"
if [ "$TRACE" != "$ERR" ]
then
echo
echo "TRACE-ERROR OUTPUT: tail $TRACE"
tail "$TRACE"
fi
fi
# remove empty log files
# : is a null command
if [ -s "$ERR" ] ; then gzip "$ERR"
elif [ -e "$ERR" ] ; then rm "$ERR"
fi
if [ -s "$OUT" ] ; then gzip "$OUT"
elif [ -e "$OUT" ] ; then rm "$OUT"
fi
if [ -s "$TRACE" ] ; then gzip "$TRACE"
elif [ -e "$TRACE" ] ; then rm "$TRACE"
fi