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
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With