Denim Datta
Denim Datta

Reputation: 3802

Cron Expression for dynamic schedule

I am looking for a Cron Expression that will schedule in different time in different weekdays. I'm not sure if that is possible or not.

I searched and found that Cron can schedule "At 8:00am every Monday through Friday" or "At 1:30am every last Friday of the month".

But is it possible to get cron expression that will schedule like, say :

10:00 AM every Monday
12:00 AM every Tuesday
02:00 PM every Wednesday
04:00 PM every Thursday
06:00 AM every Friday

I'm new to Cron Expression, and through google, I could not find whether it is possible.

My query is :

  1. Is it possible to create cron expression like that?
  2. If possible, then can you provide sample expression for that? along with some tutorial to know how to create them.

Upvotes: 0

Views: 413

Answers (1)

hkariti
hkariti

Reputation: 1719

  1. No, you need to write a different cron expression for each time-day(s) combination.

  2. Ubuntu has a nice tutorial about cron. To run something at 10:00 AM every Monday:

    # Min Hr  Day Month  Weekday   Command
      00  10  *   *      1         touch /tmp/cron_has_run
    

Note that weekdays are counted from zero, so 0 is Sunday, 1 is Monday, etc.

Upvotes: 1

Related Questions