Crontab command format

Source: Internet
Author: User

Crontab command format

1st columns minute 1 ~ 59
2nd columns hour 1 ~ 23 (0 indicates midnight)
1-3rd ~ 31
4th columns Month 1 ~ 12
5th columns in a week 0 ~ 6 (0 indicates Sunday)
6th columns of commands to run

The following is the crontab format:
Command to be run by hour, day, month, and week

Here are some examples of crontab file entries:

30 21 ***/usr/local/apache/bin/apachectl restart
The preceding example indicates restarting apache at every night.

*/1 *****/usr/local/apache/bin/apachectl restart

The example above indicates that apache is restarted every minute.

45 4, 22 **/usr/local/apache/bin/apachectl restart
The preceding example indicates that apache is restarted at on the 1st, 10th, and 22th every month.

10 1 ** 6, 0/usr/local/apache/bin/apachectl restart
The preceding example indicates that apache is restarted at every Saturday and Sunday.

0, 30 18-23 ***/usr/local/apache/bin/apachectl restart
The preceding example indicates that apache is restarted every 30 minutes between and every day.

0 23 ** 6/usr/local/apache/bin/apachectl restart
The preceding example indicates that apache is restarted at every Saturday.

0 */1 ***/usr/local/apache/bin/apachectl restart
Restart apache every hour

0 23-7/1 ***/usr/local/apache/bin/apachectl restart
Restart apache every hour between PM and PM.

0 11 4 * mon-wed/usr/local/apache/bin/apachectl restart
Restart apache on November 4 and every Monday to Wednesday.

0 4 1 jan */usr/local/apache/bin/apachectl restart
Restart apache at on January 1, January 1

 

/Slash

In a scheduled task, we often have this requirement. For example, to view the log every five minutes, we can write, 50, 55 ***/command is certainly no problem, but it is very complicated to write. to simplify it, you can write it like this: the writing of 0-55/5 ***/command is much simpler, and you still feel the trouble. You can write it like this: */5 ***/command, is it very simple and clear. This statement indicates that the command is executed every 5 minutes at, 20, 25, 30, 35, 40, 45, 50, and 55 minutes. From this we can get that the division number and range are used together to represent the step of command execution. Is the following code indicating that the command is executed every 13 minutes? */13 */command. Some step sizes cannot be expressed in this way. Only the step values that can be divisible can express exactly the same meaning as our understanding. For minutes, only */2, */3, */4, */5, */6, */10, */12, */15, */30. For hours, only */2, */3, */4, */6, */8, */12. For dates, if */5 is used, it cannot be executed once every five days. By the end of the month, it may only be executed for one day, two days, or three days, this depends on the size of the month and the ping leap year. This is because cron is stateless. It cannot record the time of the last execution. It can only judge whether execution is required based on the current time. In the */13 example, the task is executed every 13 minutes within the minute range, that is, 0-59 minutes. That is:, 52, after 8 minutes, the execution will be re-executed. Let's look at the following example: 0 6 */2 **/command. We can see that every xx execution means that the command is executed at six o'clock every two days. Here, * ranges from 1 to 31. */2 indicates that the task is executed in an odd number of days. In this case, the task is executed in 1, 3, 5, 7, 8, 10, or December, after the execution on the last day of the month and the execution on the next day, it is not executed every two days.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.