Crontab format and example

Source: Internet
Author: User
Crontab format and detailed example format: *** command indicates that the 1st column of the day-month-week command indicates minute 1 ~ 59 every minute, use * or */1 to indicate 2nd columns to indicate hour 1 ~ 23 (0 indicates 0 points) column 3rd indicates date 1 ~ 31 column 4th indicates the month 1 ~ 12 5th columns... crontab format and Example format: ***** command minute by day month week command 1st column represents Minute 1 ~ 59 every minute, use * or */1 to indicate 2nd columns to indicate hour 1 ~ 23 (0 indicates 0 points) column 3rd indicates date 1 ~ 31 column 4th indicates the month 1 ~ 12 column ID No. 0 ~ 6 (0 indicates Sunday) some examples of the command crontab file to be run in column 6th: 30 21 ***/usr/local/etc/rc. d/lighttpd restart the above example indicates restarting apache at every night. 45 4, 22 **/usr/local/etc/rc. d/lighttpd restart the preceding example indicates restart apache on 4: 45 every month on Day 1, 10, and 22. 10 1 ** 6, 0/usr/local/etc/rc. d/lighttpd restart the example above indicates that apache is restarted at every Saturday and Sunday. The preceding example of-23 ***/usr/local/etc/rc. d/lighttpd restart indicates that apache is restarted every 30 minutes from to every day. 0 23 ** 6/usr/local/etc/rc. d/lighttpd restart the preceding example indicates that apache is restarted at every Saturday. **/1 ***/usr/local/etc/rc. d/lighttpd restart apache * 23-7/1 */usr/local/etc/rc every hour. d/lighttpd restart: restart apache 0 11 4 * mon-wed/usr/local/etc/rc every hour from. d/lighttpd restart: restart apache 0 4 1 jan */usr/local/etc/rc from every Monday to Wednesday. d/lighttpd restart apache name: crontab usage permission: all users use crontab file [-u user]-use the specified file to replace the current crontab. Crontab-[-u user]-replace the current crontab with the standard input. crontab-1 [user]-list the current crontab of the user. crontab-e [user]-edit the current crontab of the user. crontab-d [user]-delete the current crontab of the user. crontab-c dir-specifies the crontab directory. Crontab file format: m h d m d cmd. M: minute (0-59 ). H: Hour (0-23 ). D: Day (1-31 ). M: month (1-12 ). D: days in a week (0 ~ 6, 0 is Sunday ). The program to run in cmd is sent to sh for execution. the shell only contains three environment variables: USER, HOME, and SHELL: 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. Parameter: crontab-e: run the text editor to set the time table. the preset text editor is VI. if you want to use another text editor, first, set the VISUAL environment variable to specify the text editor (for example, setenv VISUAL joe) crontab-r: delete the current time table crontab-l: 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 where f1 represents minutes, f2 represents hours, f3 represents the day of a month, and f4 represents the month, f5 indicates the day of the week. Program indicates the program to be executed. When f1 is *, the program is executed every minute. if f2 is *, the program is executed every hour, and so on. when f1 is a-B, it indicates that it will be executed from minute a to minute B, when f2 is a-B, it indicates that execution is performed from Hour a to hour B, and so on. when f1 is */n, it indicates that execution is performed every n minutes, if f2 is */n, the task is executed every n hours. Similarly, when f1 is a, B, c ,... a, B, c ,... execute in minutes. f2 is a, B, c ,... a, B, c... you can save all settings in the file and use crontab file to set the time table. Example: # run/bin/ls at every morning: 0 7 ***/bin/ls at PM every morning within March 31, December, run once every 3 hours/usr/bin/backup: 0 6-12/3*12 */usr/bin/backup from Monday to Friday send a letter to alex@domain.name at every day: 0 17 ** 1-5 mail-s "hi" alex@domain.name </tmp/maildata every day at midnight 00:20, 02:20, 04:20 .... run 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, display the content of the program execution. if you do not want to receive such a message, add>/dev/null 2> & 1 after each line with an empty box to 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 #4 of each month and 11: 0 11 a.m. from Monday to wed date of every week # a.m. of February 4: 0 4 1 jan * date example $ crontab-l lists the current crontab of a user.
 
Related Article

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.