views:

71

answers:

3

Is it possible to write cron expression for trigger that must fire every day and every minute from 12:04 to 14:25?

+2  A: 

I think the shortest solution (using cron) are these 3 lines

4-59 12 * * * <command>
0-59 13 * * * <command>
0-25 14 * * * <command>

They define the trigger ranges for each hour.

Veger
The quartz cron format takes the seconds as well.
laura
A: 

You'll have to set 3 diff cron jobs:

    .---------------- minute (0 - 59) 
    |  .------------- hour (0 - 23)
    |  |   .---------- day of month (1 - 31)
    |  |   |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
    |  |   |  |  .---- day of week  
    |  |   |  |  |
  4-59 12  *  *  *  <command to be executed>
  0-59 13  *  *  *  <command to be executed>
  0-25 14  *  *  *  <command to be executed>
codaddict
+1  A: 

You tagged quartz so here is an example taken from the docs at http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html

0 * 12-14 * * ? would fire every minute every day between 12:00 and 14:59.

Judging by the example "0 0/5 14,18 * * ?" Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day in the web page i linked to, you may be able to do something like

0 4-59,0-59,0-25 12,13,14 * * ?

but I'm not sure that would work because it looks a bit dubious, and the docs don't say how the minutes/hours are interpreted if you write it like that. If it doesn't work, you have to define three triggers:

0 4-59 12 * * ?
0 * 13 * * ?
0 0-25 14 * * ?
laura