Ubuntu: How to Force a Silent Cron CodeUnit 04 JAN 2011

By default, cron actions that produce output generates emails that get sent to the system administrator. If we don’t particularly want this behaviour, we need to terminate our function calls with a specific character sequence, which looks as follows:

5 * * * * /usr/mine/script > /dev/null 2>&1

The first part of the statement sends the output to the “bit bucket” (> /dev/null) which is basically the same as throwing it away. The second part of the call (2>&1) forces all generated stderror error messages to follow the stdout messages, which in this case we’ve already pointed towards the “bit bucket”.

Simple, and effective, if you don’t want to be bothered by a whole lot of non-critical cron jobs!

About Craig Lotter

Software developer, husband and dad to two young ladies. Writer behind An Exploring South African. I don't have time for myself any more.