NewBeee_Java
NewBeee_Java

Reputation:

Cron expression for particular date

I want a cron expression that represents 6th September 2010 6:00 am

Upvotes: 29

Views: 80692

Answers (4)

Kasthuri Shravankumar
Kasthuri Shravankumar

Reputation: 679

This will help you.

At 02:30:00am, on the 23rd day, in April, in 2024

https://www.freeformatter.com/cron-expression-generator-quartz.html enter image description here

Upvotes: 2

paxdiablo
paxdiablo

Reputation: 881253

Original question was tagged cron so this first section applies to that. See below for an updated answer for the Quartz CronTrigger tool.


Most crontabs don't let you specify the year so you'll probably have to put that in the script itself (or a wrapper around the script/program).

You can do this with something like:

# Only run in 2010.
if [[ $(date +%Y) != 2010 ]] ; then
    exit
fi

The option you're looking for to run at 6am on September 6 every year is:

0 6 6 9 * your_command_goes_here
│ │ │ │ │
│ │ │ │ └─ any day of the week.
│ │ │ └─── 9th month (September).
│ │ └───── 6th day of the month.
│ └─────── 6th hour of the day.
└───────── Start of the hour (minutes = 0).

For the Quartz CronTrigger format, you'd be looking at something like:

0 0 6 6 9 ? 2010
│ │ │ │ │ │   │
│ │ │ │ │ │   └─ 2010 only.
│ │ │ │ │ └───── any day of the week.
│ │ │ │ └─────── 9th month (September).
│ │ │ └───────── 6th day of the month.
│ │ └─────────── 6th hour of the day.
│ └───────────── Start of the hour (minutes = 0).
└─────────────── Start of the minute (seconds = 0).

Upvotes: 37

PajaS
PajaS

Reputation: 61

It could be only in /etc/crontab by follows:

0 6 6 9 * root test `/bin/date +%Y` == 2010 && <your command>

Upvotes: 6

tbalazs
tbalazs

Reputation: 599

For one-shot jobs the 'at' command is better suited than cron.

at -f filename 06:00 09/06/2010

Upvotes: 9

Related Questions