简体   繁体   中英

How to setup CRON job to run every 10 minutes exactly from 9:24:59 to 15:14:59?

I need to setup 2 cron jobs with very precise timing for my PHP code.

Cron 1:

Run cron job every 10 minutes, every day between 9:24:59 to 15:14:59. ie cron job starting from every morning 9 hours 24 minutes 59 seconds to afternoon 15 hours 14 minutes 59 seconds. The cron should run every 10 minutes, example:

9:24:59
9:34:59
9:44:59
9:54:59
...
14:54:59
15:04:59
15:14:59

Cron 2:

Run cron job every 10 minutes, every day between 9:15 to 15:05. For example:

9:15
9:25
9:35
9:45
...
14:45
14:55
15:05

To make it run any process every 10 minutes just add:

*/10 * * * *

I would make my limitations of time from my PHP function.

Crontabs说明

Source

You can specify the time range for the script in the crontab file using bash syntax. For example see: Cron jobs and random times, within given hours and How to check if the current time is between 23:00 and 06:30 .

Using bash commands in a single line can be difficult to understand and maintain. A simpler option is to use 3 cron tab entries. The first entry will run the script every 10 min from 09:25 to to 09:55. The second entry will run the script every 10 min from 10:05 to 14:55. The third entry will run the script from 15:05 to 15:15. These three crontab entries will cause the script to run at 09:25, 09:35, 09:45 .... 15:15. Following are the three crontab entries:

25-55/10 9 * * * script-path
5-55/10 10-14 * * * script-path
5-15/10 15 * * * script-path

You should confirm that the script runs at the correct times

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM