38

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
cuonglm
  • 150,973
  • 38
  • 327
  • 406
user3475
  • 493
  • 1
  • 4
  • 5
  • 3
    See [What is the difference between > and >> (especially as it relates to use with the cat program)?](http://unix.stackexchange.com/questions/46974/what-is-the-difference-between-and-especially-as-it-relates-to-use-with-th), [What does “3>&1 1>&2 2>&3” do in a script?](http://unix.stackexchange.com/questions/42728/what-does-31-12-23-do-in-a-script) and of course, your shell's manual. (There are some further explanations in [Is this a typo in Bash manual's redirection section?](http://unix.stackexchange.com/questions/84279/is-this-a-typo-in-bash-manuals-redirection-section) too.) – manatwork Sep 04 '13 at 10:08
  • @mana ....thanks a lot very useful articles.. – user3475 Sep 05 '13 at 04:02

2 Answers2

61

> 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.

sergut
  • 1,869
  • 14
  • 11
9

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.

terdon
  • 234,489
  • 66
  • 447
  • 667
cuonglm
  • 150,973
  • 38
  • 327
  • 406
  • Thanks a lot. It really helps. Now I understood Google can't give everything. Experts advice always best :) – user3475 Sep 04 '13 at 12:54