What does "2>&1" do in crontab?
Example:
01 * * * * /oracle/work/ak/test.sh >/oracle/work/ak/logtest.out 2>&1
The command 2>&1 is to prevent crontab sending an email (sendmail on /var/mail/root) when the script fails. so, if the error occurs when the crontab script fails, then the email will dump to logtest.out not on /var/mail/root.
here we go,
The 2>&1 just redirects Channel 2 (Standard Error) and Channel 1 (Standard Output) to the same place which in this context is Channel 1 (Standard Output), and thence your log file.
If all output from a cron is redirected to a file, it will not generate an email of the output to Stdout or Stderr.
Hope this helps ;-)
Example:
01 * * * * /oracle/work/ak/test.sh >/oracle/work/ak/logtest.out 2>&1
The command 2>&1 is to prevent crontab sending an email (sendmail on /var/mail/root) when the script fails. so, if the error occurs when the crontab script fails, then the email will dump to logtest.out not on /var/mail/root.
here we go,
The 2>&1 just redirects Channel 2 (Standard Error) and Channel 1 (Standard Output) to the same place which in this context is Channel 1 (Standard Output), and thence your log file.
If all output from a cron is redirected to a file, it will not generate an email of the output to Stdout or Stderr.
Hope this helps ;-)