Redirect Output and Errors to /dev/null
I have alot of scripts
running in cronjob and somethimes they fail I don’t want to get the
out. If you run scripts of the command line, the standard thing to do
is to add > /dev/null to redirect output to the bitbucket instead.
On cronjobs it’s different the stderr is send as email to the owner.
So if you don’t care about the about of a sertend script you can differ
the output.
The graceful way to handle this in any shell is as follows: Redirect
the output of stderr to stdout, and then redirect this combined output
to /dev/null:
./script.sh > /dev/null 2>&1
What happens here is as follows:
- We send standard output to /dev/null, using > /dev/null.
- 2>&1 – ensures that you send the standard error (file
descriptor 2), to wherever standard output (file descriptor 1) is
going, which is, as already established, to the bitbucket.