Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Cronjob to Run Every 5 Minutes From 9:30am to 4:00pm

I need to set a cronjob to run a bash script every 5 minutes, starting at 9:30am until 4:00pm.

I have the following but, it's not quite right...

Cronjob:

*/5 9-16 * * * /path/to/directory/job.sh > /path/to/log/file/job.log 2>&1
like image 403
Aaron Perry Avatar asked Nov 06 '15 02:11

Aaron Perry


1 Answers

What you have there is a line that will run the command every five minutes between 09:00 and 16:55 (all ranges here are inclusive).

What you're trying to achieve can be done relatively simply with three separate crontab lines:

30-59/5 9     * * * /path/to/directory/job.sh > /path/to/log/file/job.log 2>&1
*/5     10-15 * * * /path/to/directory/job.sh > /path/to/log/file/job.log 2>&1
0       16    * * * /path/to/directory/job.sh > /path/to/log/file/job.log 2>&1

The first handles the case between 09:30 and 09:55, the second every five minutes between 10:00 and 15:55, and the final one the single job at 16:00.

like image 138
paxdiablo Avatar answered Oct 15 '22 07:10

paxdiablo