Crontab scheduled task
Crontab (scheduled task operation)
Edit command: crontab-e
View command: crontab-l
# For details see man 4 crontabs
# Example of job definition:
#.-minute (0-59)
# |.-hour (0-23)
# | |.-day of month (1-31)
# |.-month (1-12) OR jan,feb,mar,apr...
# |.-day of week (0-6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |
# * user-name command to be executed
The format is as follows:
Minute hour day month week user-name command
Minute--- minutes (0-59)
Hour- hours (0-23)
Day- date (1-31)
Month--- month (January-December)
Week---- week (0-6) / / 0 represents Sunday
In addition to numbers, there are several special symbols, namely "*", "/" and "-", * represents all the numbers in the range of values, "/" represents each, "* / 5" means every five units, "-" represents from a number to a number, "," separate several discrete numbers. Here are a few examples:
Example:
1 * / tmp/test.sh
Indicates that the script is executed at the first minute of each hour
2 3 * / tmp/test.sh
Indicates that the script is executed at 3: 02 every day
1 1 * * 0 / tmp/test.sh
Represents the execution of the script at 01:01 every week
1 1 1 * / tmp/test.sh
Represents the execution of the script at 01:01 every month
It is easier to make the mistake of doing the first minute of each hour once per minute. Note the difference between the two:
1 * / tmp/test.sh
Indicates that the script is executed at the first minute of each hour
* / 1 * / tmp/test.sh
Represents the execution of the script every minute
So keep in mind the difference brought about by the symbol "/" here.
The usage of "-":
0 10 * * 1-3 / tmp/test.sh
It means to execute the script at 10:00 every Monday through Wednesday morning.
0 10 * 1, 3, 5 / tmp/test.sh
It means to execute the script at 10:00 on Monday, Wednesday and Friday every week.