MalcolmInTheCenter
MalcolmInTheCenter

Reputation: 1605

How do I setup a cron job to run every 3 hours from afternoon to midnight?

I need to create a cron job that run every 3 hours from 12 pm to 12am so it would run at 12pm 3pm 6pm 9pm and 12 am. I have a cron script running on AWS Lambda and they have 6 fields for the cron time. I think it was to be something along the lines of:

0 */3 * * * *

but I know this is wrong, can't figure it out. How can I do this?

I've tried

0 0,12,15,18,21  * * *

but I get this error: http://screencast.com/t/7tH2wnseyc

There was an error creating the event source mapping: Parameter ScheduleExpression is not valid.

Upvotes: 4

Views: 14892

Answers (4)

Doug Hudgeon
Doug Hudgeon

Reputation: 1539

AWS Cloudwatch Events currently requires a question mark in either the day-of-week or day-of-month slot. Here is the cron expression I used to do accomplish the task:

0 12,15,18,21,0 * * ? *

In Cloudwatch Events, you can now tell if you're on the right track because it displays trigger dates below your expression

cron expression

Upvotes: 7

dboals
dboals

Reputation: 610

according to https://en.wikipedia.org/wiki/Cron you can use commas create a list for a given field so something like should work

0 0,12,15,18,21  * * *

This will run at 12, 3, 6, 9, and midnight at the top of the hour. If the Cron format wants a year then add another *

0 0,12,15,18,21  * * * *

Upvotes: 6

Dukefirehawk
Dukefirehawk

Reputation: 476

Based on http://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html

cron(0 0/3 * * * *)

should do the trick.

Upvotes: 3

Techsavy
Techsavy

Reputation: 23

Use the following

0 0,12,15,18,21 * * * /path/command  

where the cron runs at 00:00, 12:00, 15:00, 18:00, 21:00 each day.

Upvotes: 0

Related Questions