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.
i.e 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
2
Answers
To make it run any process every 10 minutes just add:
*/10 * * * *
I would make my limitations of time from my PHP function.
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:
You should confirm that the script runs at the correct times