Basic format:
* * * * * command
Time-sharing Weekly command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to execute
Some examples of crontab files:
* * * * */usr/local/etc/rc.d/lighttpd restart
The example above represents a 21:30 restart of Apache per night.
4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The example above indicates that the Apache is restarted at 4:45 per month for 1, 10, 22nd.
1 * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The example above shows the 1:10 restart Apache per Saturday, Sunday.
0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart
The example above indicates that Apache is restarted every 30 minutes from 18:00 to 23:00 every day.
0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The example above indicates that the Apache is restarted every Saturday at 11:00am.
* */1 * * * */usr/local/etc/rc.d/lighttpd restart
Restart Apache every hour
* 23-7/1 * * * */usr/local/etc/rc.d/lighttpd restart
Between 11 o'clock and 7 in the morning. Restart Apache every hour
0 4 * mon-wed/usr/local/etc/rc.d/lighttpd restart
4th per month with 11-point restart from Monday to Wednesday Apache
0 4 1 Jan */usr/local/etc/rc.d/lighttpd restart
January 1 4-point restart Apache
Name: crontab
Usage rights: All users
How to use:
crontab file [-u user]-replaces the current crontab with the specified files.
Crontab-[-u user]-replaces the current crontab with standard input.
crontab-1[user]-lists the users ' crontab at the moment.
crontab-e[user]-Edit the user's current crontab.
crontab-d[user]-Delete the user's current crontab.
Crontab-c dir-Specifies the folder for crontab.
Format of the crontab file: M H d M D cmd.
M: Minutes (0-59).
H: Hours (0-23).
D: Day (1-31).
M: Month (1-12).
D: Days within a week (0~6. 0 for Sunday).
CMD to execute the program, the program is fed into SH execution. This shell has only user,home,shell these three environment variables
Description
Crontab is used to allow users to run programs at fixed or fixed intervals. Other words. This is the time table for similar users. -u user refers to setting the specified
User's time table, which presupposes that you must have permission (for example, root) to specify another's time schedule. Assume that you do not use the-u user. is to indicate the setting
Set your own schedule.
Number of references:
CRONTAB-E: Run the text editor to set the time table, the default text editor is VI, if you want to use another text editor, please set the VISUAL environment variables first
To specify the use of that text editor (say 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.
The format of the schedule table is as follows:
F1 F2 F3 f4 f5 program
The F1 is a minute, F2 represents the Hour, F3 represents the day of the month, F4 represents the month, and F5 represents the day of the one week. program says
The program of the line.
The program is run every hour when F1 is * to indicate that every minute you run PROGRAM,F2 to *. The remainder of the analogy
When the F1 is a-B, it is said to run from the minute of a to the minute, and F2 is a-B to run from the first to the first
When F1 is */n, it is run once per n minute interval. F2 for */n, which runs every n-hour interval, with the remainder of the analogy
When F1 is a, B, C,... A, B, C,... Minutes to run. F2 is a, B, C,... The time indicated that the first, B, c ... Hours to run, and the rest of the analogy
The user is also able to store all the settings in the file file, using crontab file to set the time schedule.
Examples:
#每天早上7点运行一次/bin/ls:
0 7 * * */BIN/LS
In December, every 3 hours in the morning from 6 to 12 o '/usr/bin/backup:
0 6-12/3 */usr/bin/backup
Monday to Friday every 5:00 send a letter to [email protected]:
0 * * 1-5 mail-s "HI" [email protected] </tmp/maildata
Every day of the month 0:20 midnight, 2:20, 4:20 .... Run echo "haha"
0-23/2 * * * echo "haha"
Attention:
When the program runs at the time you specify. The system will send you a letter showing the contents of the program running, if you do not want to receive this letter. In each line, empty one
After adding >/dev/null 2>&1 can
Example 2:
#每天早上6点10分
6 * * * Date
#每两个小时
0 */2 * * * Date
#晚上11点到早上8点之间每两个小时. 8 in the morning.
0 23-7/2,8 * * * Date
#每一个月的4号和每一个礼拜的礼拜一到礼拜三的早上11点
0 4 * mon-wed date
#1月份日早上4点
0 4 1 Jan * Date
Cases
$crontab-L lists the user's immediate crontab.
Linux crontab syntax and specific examples