/dev/null

Hi expert,

May I know what is the difference between below cron tab entry ?

0,12 * * * * /abc/myscript.sh > /dev/null 2>&1

0,12 * * * * /abc/myscript.sh

0,12 * * * * /abc/myscript.sh > /dev/null 2>&1

redirect the stdout to /dev/null
2>&1
means redirect all the stderr to where stdout is redirected therefore to /dev/null

In other words, standard output and error messages are ignored.

The alternative is, with nowhere else to go, it gets emailed to the user whose crontab it is.

Ok thanks.
What if a sendmail daemon is not running ? still gets emails ?
Is it a good practice to add /dev/null 2>&1 in crontab entry ?

Sendmail not running? Good question. I would assume it gets queued until sendmail is running again, but isn't queing it a function of sendmail? Bottom line: I don't have an answer.

Good practice? Personally, I'd say no. You may want to divert the STANDARD output to /dev/null but errors too? That really depends upon the application.

The sendmail daemon needs to be up and running for incoming emails only not for outgoing ones. For outgoing ones the daemon is invoked as and when needed to push out mails that are in the queue.

Hi Dave, thanks for the reply. I'm just running a script containing a few command for collecting statistics and health of the server and someone told me if i don't add /dev/null 2>&1 entry . The system might crash due to mail queue.

honestly I don't get it . That's why I'm asking. I'm looking for a method/tricks to disable crontab from sending mail. If you know how to do it. Pls show me ?

Not really

I would say its a good practice to redirect STDOUT and STDERR to a log file. When something is not working you have logs to check that.