I know every five minutes is:
0 0/5 * * * *
But how do I limit the number hours for this to happen?
Example: Every five minutes for the next 10 hours.
Make a new line at the bottom of this file and insert the following code. Of course, replace our example script with the command or script you wish to execute, but keep the */5 * * * * part as that is what tells cron to execute our job every 5 minutes.
Run a Cron Job Every 5 Minutes*/5 means create a list of all minutes and run the job for every fifth value from the list.
It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .
Run a Cron Job after every 10 minutes The slash operator helps in writing the easy syntax for running a Cron job after every 10 minutes. In this command, */10 will create a list of minutes after every 10 minutes.
Use the range operator to specify the hours. For example, for running the job every five minutes for 10 hours starting at 2 am:
0 0/5 2-12 * * *
Here is an excellent tutorial on Cron expression and operators: http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html
Edit: 10/3/2016: Updated the link.
I think should be able to define a trigger that can repeat every hour until a certain time:
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;
...
Trigger myTrigger = newTrigger()
.withIdentity('myUniqueTriggerID")
.forJob(myJob)
.startAt(startDate)
.endAt(endDate)
.withSchedule(simpleSchedule().withIntervalInHours(1));
...
scheduler.scheduleJob(myJob, myTrigger);
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