Crapper
Another old favourite, a short but constantly use script.
When jobs are run from cron any output send to standard output or error is helpfully emailed to the user. However lots of programs and scripts output stuff that is only really of interest when things go wrong but will spew forth to standard output anyway. So to reduce the volume of email I have a cron wrapper script, crapper, that will collect the output and only send it if there has been an error.
#!/usr/bin/ksh
trap '${TMPFILE:+rm ${TMPFILE}}' EXIT
TMPFILE=$(mktemp ${TMPDIR:-/tmp}/${0##*/}.temp.XXXXXX)
$@ > $TMPFILE 2>&1 || cat $TMPFILE
used from cron:
2 1 1 * * exec /usr/local/bin/crapper /tank/fs/local/snapshot month tank/fs
Sweet and simple.
Hi Chris,
I’m maintaining a small collection of scripts which I use regularly (http://bitbucket.org/andunix/scripts/src). As the above script is very useful, I would like to include it, along with the blog entry as explanation.
I couldn’t find any statement about the license of the contents of your blog, so I have to ask: Do you allow sharing of your contents and under which constraints?
Cheers,
Andreas
Andreas,
Feel free to use it as you wish. Since you are polite enough to ask I’m sure you would attribute it anyway.
–chris