My colleague told me the commabd 2>&1 mean to prevent crontab sending an email (sendmail on /var/mail/root) when the script failed. So, if error occur when the crontab script failed, the email will dump to logtest.log not on /var/mail/root.
Is it true?
Why system always sending email if crontab script failed? and with adding command 2>&1 can solve the problem?
Your colleague is correct. 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.
If you want to do the redirection on the crontab line this the best solution based on the information supplied.
It would really help if you posted what Operating System and version you are running (okay we know that is is a Solaris) and what Shell you are using when in crontab. Under Solaris the Shell under cron can be an ancient Bourne Shell.