Name: crontab Permission: All Users Usage: Crontab [-u user] File Crontab [-u user] {-L |-r |-e} Note: Crontab is used to allow users to execute programs at a fixed time or interval. In other words, it is similar to the user's time table. -U user is used to set the time table of the specified user. The premise is that you must have the permission (for example, root) to specify the time table of another user. If-u user is not used, the time table is set. Parameters: Crontab-E: Execute the text editor to set the time table. The preset text editor is vi. If you want to use another text editor, set the visual environment variable to specify the Text Editor (for example, setenv visual Joe) Crontab-R: Delete the current time table Crontab-L: to list the current time table Crontab file [-u user]-replace the current crontab with the specified file. The time table format is as follows: F1 F2 F3 F4 F5 Program F1 indicates the minute, F2 indicates the hour, F3 indicates the day of the month, F4 indicates the month, and F5 indicates the day of the week. Program indicates the program to be executed. When F1 is *, the program is executed every minute. When F2 is *, the program is executed every hour, and so on. When F1 is a-B, it indicates that execution is performed from the minute a to the minute B. When F2 is a-B, it indicates that execution is performed from the hour a to the hour B, and so on When F1 is */N, it indicates execution is performed every n minutes. If F2 is */N, it indicates execution is performed every n hours, and so on. When F1 is a, B, c ,... a, B, C ,... execute in minutes. F2 is a, B, c ,... a, B, c... execution in hours, and so on You can also store all settings in the file first, and use crontab file to set the time table. Example 1: # Run/bin/ls at every morning: 0 7 ***/bin/ls During October 11, December, execute/usr/bin/backup every three hours from to every day: 0 6-12/3*12 */usr/bin/backup From Monday to Friday, send a letter to alex@domain.name at pm: 0 17 ** 1-5 mail-s "hi" alex@domain.name every day at midnight 00:20, 02:20, 04:20... execute echo "Haha" 20 0-23/2 *** echo "Haha" Note: When the program is executed at the specified time, the system will send you a letter showing the program execution content. If you do not want to receive such a letter, add>/dev/null 2> & 1 after each line is empty. Example 2: #06:10 every morning 10 6 **** date # Every two hours 0 */2 * Date # Every two hours from PM to am, am 0 23-7/2, 8 **** date # Am on the 4th day of each month and from Monday to Wednesday of each week 0 11 4 * Mon-wed date # A.m. of July 0 4 1 Jan * Date
|