views:

74

answers:

1

I would like to schedule a cron task to run every hour, but only from Thursday through Monday. Is a schedule like this possible? From the documentation, it looks like I can schedule a cron task to run at an hourly interval or on specific days at a single specific time, but I cannot figure out how to schedule a cron task to run at an hourly interval only on specific days.

I've tried schedules like the following in cron.yaml:

  • every 1 hours thu,fri,sat,sun,mon
  • every 1 hours of thu,fri,sat,sun,mon

The way I read the documentation, I think this may be impossible. I'm hoping that I've either missed something or that there is some undocumented syntax for what I'm trying to accomplish.

+1  A: 

Like you noticed in the documentation for cronjobs, the source also seems to indicate that the interval schedule format doesn't let you restrict the interval to particular day(s) of the week.

Though you can't schedule your task with a single cronjob, you could schedule it with multiple cronjobs:

every thu,fri,sat,sun,mon 00:00
every thu,fri,sat,sun,mon 01:00
...
every thu,fri,sat,sun,mon 23:00

Alternatively, leoluk's comment makes a good suggestion - just use a single, simple interval schedule which invokes your script every hour, but have your script terminate without doing anything if the day of week is one which you wish to exclude (e.g., Tuesday or Wednesday in your case).

David Underhill
Yeah, it sounds like just checking the day at the start of the script is probably the right option.
Will McCutchen
Note: There's a comment in the source which indicates that the schedule syntax could be expanded to allow multiple hours to be specified - then you could collapse the 24 jobs into one job. So perhaps in the future you could replace the in-script check with a single cronjob (a longish line, but better than the 24 jobs that would be required to achieve your goal solely through cron).
David Underhill