Crontab Timing Scheduling

Source: Internet
Author: User

First, configure the environment

System: CentOS

First Execute:

Crontab-  L  

The system cannot find the command "-bash:crontab:command not found" if it appears

You need to install the package "Vixie-cron", "Crontab"

Yum Install   -yvixie-yuminstall   crontab

Execute crontab-l again, if "No crontab for Root" appears, execute CRONTAB-E create a new empty file in vi edit mode, press shift+: Exit, Hint: crontab:installing new Cront AB executes crontab-l at this time, without prompting the installation succeeds.

crontab Command Common parameters:

-e means editing the current crontab

-L indicates that the list displays the current crontab task

-R means to delete the current user's crontab

-I gives prompt message when deleting crontab

Second, configuration instructions

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 run

Some examples of crontab files:

* * * */usr/local/etc/rc.d/lighttpd Restart
The above example shows that 21:30 restarts Apache per night.

4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month.

1 * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 1:10 restarts Apache every Saturday and Sunday.

0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that Apache restarts every 30 minutes from 18:00 to 23:00 every day.

0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows the restart of Apache 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
From 11 o'clock to 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
4-point restart of Apache on January 1

Execute */5 every five minutes * * * *

Executes 0 per hour * * * *

Executes 0 0 * * * per day

Weekly Execution 0 0 * 0

Monthly execution 0 0 1 * *

Annual Execution 0 0 1 1 *

Third, configure timing scheduling

Execute the VI command to edit the scheduled schedule list.

Vi/etc/crontab

Execute PHP code as per minute schedule as follows

#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#Custom Schedule executes once per minute*/1 * * * * * root php/www/php/my.php>>/www/php/my.Log

Crontab Timing Scheduling

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.