Skip to content

Crapper

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.

#!/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.

Advertisements
2 Comments
  1. 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

  2. chrisgerhard permalink

    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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: