One, write format:
* * * * * command
Minute hour day Month Week command
which
- Minute: Represents minutes, which can be any integer from 0 to 59.
- Hour: Represents the hour, which can be any integer from 0 to 23.
- Day: Represents a date, which can be any integer from 1 to 31.
- Month: Represents the month, which can be any integer from 1 to 12.
- Week: Represents the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.
- Command: The commands to execute can be either system commands or script files that you write yourself.
- CRONTAB-E: Do a text editor to set the time table, the default text editor is VI, if you want to use a different text editor, you first set the VISUAL environment variables to specify the use of the text editor (for example, setenv visual Joe)
- Crontab-r: Delete the current schedule table
- Crontab-l: List the current schedule
- crontab file [-u user]-replaces the current crontab with the specified files.
Second , most of the crontab planning tasks will be years to the end of the >/dev/null 2>&1, what is the meaning of it?
- > is redirect
- /dev/null represents an empty device file
- 1 means stdout standard output, the system default is 1, so ">/dev/null" is equivalent to "1>/dev/null"
- 2 indicates stderr standard error
- & means equivalent to, 2>&1, 2 output redirect equals 1
- The meaning of the sentence is that the standard output is redirected to an empty device file, that is, does not output any information to the terminal, the standard error output redirect is equivalent to the standard output, because the standard output has been redirected to the empty device file, so the standard error output is redirected to the empty device file
What is the difference between command > file 2>file and command > file 2>&1?
- Command > File 2>file means that the standard output information generated by the command is sent to file with the wrong output information. Command > File 2>file StdOut and stderr are sent directly to file, file will be opened two times, so stdout and stderr will cover each other, so write quite use FD1 and FD2 two simultaneously to seize the file of the pipeline.
- and command >file 2>&1 This order will stdout directly sent to file, stderr inherit the FD1 pipeline, and then sent to file, at this time, file was opened only once, also only used a pipeline FD1, It includes the contents of stdout and stderr.
- From IO efficiency, the efficiency of the previous command is less efficient than the following command, so when writing a shell script, we use command > file 2>&1.
Sample Description:
* * * * python/home/sysuser/shell/hello.py >/home/sysuser/shell/hello.log 2>&1
The above example: every day, 3:10 A.M. executes the hello.py, and then writes the log to the Hello.log
Above example: 1, 10, 22nd of the 4:45 restart Apache.
The above example: 1:10 restart Apache per Saturday, Sunday
4th per month with 11-point restart from Monday to Wednesday Apache
Linux commands (6) Usage and parsing of crontab