I have a CRONTAB entry as below. Can someone tell me what the below statement is exactly doing?
1 0 * * * /vol01/sites/provisioning/MNMS/45627/45627.sh1 >> /vol01/sites/provisioning/MNMS/45627/output/cron.log 2>&1
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
> redirects output to a file, overwriting the file.
>> redirects output to a file appending the redirected output at the end.
Standard output is represented in bash with number 1 and standard error is represented with number 2. They are separate, so the user can redirect them to different files.
2>&1 redirects the standard error to the standard output so they appear together and can be jointly redirected to a file. (Writing just 2>1 would redirect the standard error to a file called “1”, not to standard output.)
In your case, you have a job whose output (both standard and error) is appended at the end of a log file (cron.log) for later use.
For additional info, check the bash manual (section “Redirection”), this question, and this question.
Method 2
You should google with keyword bash redirection for some detailed information. Here is a nice article for reference.
For your question, the crontab will run 45627.sh1 scripts at 00:01 everyday and append its error and output to the cron.log file.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0