Skip to content


March 27, 2010

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.


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.

  1. Hi Chris,

    I’m maintaining a small collection of scripts which I use regularly ( 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?



  2. chrisgerhard permalink


    Feel free to use it as you wish. Since you are polite enough to ask I’m sure you would attribute it anyway.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: