views:

260

answers:

3

How can i set up my crontab to execute X script at 11:59PM every day without emailing me or creating any logs?

Right now my crontab looks something like this

@daily /path/to/script.sh

+9  A: 

When you do crontab -e, try this:

59 23 * * * /usr/sbin/myscript > /dev/null

That means: At 59 Minutes and 23 Hours on every day (*) on every month on every weekday, execute myscript.

See man crontab for some more info and examples.

Michael Stum
+4  A: 

you will with the above response recieve email with any text written to stderr. Some people redirect that away too, and make sure that the script writes a log instead.

... 2>&1 ....
svrist
+4  A: 

Following up on svrist's answer, depending on your shell, the 2>&1 should go after > /dev/null or you will still see the output from stderr.

The following will silence both stdout and stderr:

59 23 * * * /usr/sbin/myscript > /dev/null 2>&1

The following silences stdout, but stderr will still appear (via stdout):

59 23 * * * /usr/sbin/myscript 2>&1 > /dev/null

The Advanced Bash Scripting Guide's chapter on IO redirection is a good reference--search for 2>&1 to see a couple of examples.

Dominic Cooney