0

I have a difficulty writing a cron expression to schedule events Mon-Saturday every 15 minutes from 4:30 am to 8:30 am.

Thanks.

David Shochet
  • 5,035
  • 11
  • 57
  • 105

2 Answers2

2

I don't think that you can solve this problem in one step, so a usable strategy might be to first coarse-filter via crontab:

0,15,30,45 4,5,6,7,8 * * 1,2,3,4,5,6 /do-whatever

which is almost OK, it will just execute 4:00 4:15 and 8:45, so we filter these at the start of the executed script:

# Too early?  Then get out
if [ `date +%H%M` -lt 430 ] ; then
   exit 0
fi
# Too late?  Then get out
if [ `date +%H%M` -gt 830 ] ; then
   exit 0
fi
# start of the original script
....
fvu
  • 32,488
  • 6
  • 61
  • 79
  • Thanks... But I really need it in one expression... Would it be possible, if I simplify it to run from 4 to 9? Would not this do it: */15 4-8 * * 1-6 – David Shochet Aug 12 '13 at 18:37
  • 1
    Well obviously that would work, because you remove the very issue that makes this hard :-). I just wrote out the statements in full, because I thought it was easier to understand. – fvu Aug 12 '13 at 21:07
0

It will take 3 separate Quartz cron expressions to define the times exactly as you want them.

0 30 4,5,6,7,8 ? * MON,TUE,WED,THU,FRI,SAT *
0 45 4,5,6,7 ? * MON,TUE,WED,THU,FRI,SAT *
0 0,15 5,6,7,8 ? * MON,TUE,WED,THU,FRI,SAT *

Edited to add: This Quartz cron expression gets you from 4 am to 8:45 am, just as fvu's answer does.

0 0/15 4-8 ? * MON,TUE,WED,THU,FRI,SAT *
Community
  • 1
  • 1
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111