Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Cron expression to run every two days from the current day

sivachithambaram Rangaraj
Greenhorn
Posts: 5
Hi,

How to write a cron expression to execute on every two days from the current day.

I have used one expression like "1 0 18 */2 * ?" but it is firing only in the odd days.. i guess becaz it is starting it from day 1 of the month.

So can anyone help on this?

Thanks
Siva

Sagar Rohankar
Ranch Hand
Posts: 2907
1
sivachithambaram Rangaraj wrote:
I have used one expression like "1 0 18 */2 * ?" but it is firing only in the odd days.. i guess becaz it is starting it from day 1 of the month.

You mean the cron expression firing correctly after each 2 days, in your case, starting from 1, :
1 3 5 so on...
Thats what you want, right OR you want even/odd days execution ??
For latter case, try using "2/2" - "fire every 2 days starting on the second day of the month".

http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html

sivachithambaram Rangaraj
Greenhorn
Posts: 5

My scenario is like if i schedule it on 10th of feb the job should be executed for every n days starting on 10th feb ..not on the even days alone or not on the odd days alone...the intereval may vary from 1 to n...

sivachithambaram Rangaraj
Greenhorn
Posts: 5
I solved it by building a simple trigger with the specified interval multiplied by 24..

i.e Trigger t=Triggerutils.makeHourlyTrigger(interval*24);'
This will trigger for every n days ..

Thanks
Siva

Sagar Rohankar
Ranch Hand
Posts: 2907
1
sivachithambaram Rangaraj wrote:Thanks rohan ,for the reply..

sivachithambaram Rangaraj wrote:My scenario is like if i schedule it on 10th of feb the job should be executed for every n days starting on 10th feb ..not on the even days alone or not on the odd days alone...the intereval may vary from 1 to n...

Then I think, your expression should work.
I solved it by building a simple trigger with the specified interval multiplied by 24..

Are you sure, multiplying it by 24 hours solves your original requirement, i'e firing after each 2 days

Sagar Rohankar
Ranch Hand
Posts: 2907
1
Also, any moderator watching this thread, please move it to "Other JSE/JEE API" section.

Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35095
380
Sagar Rohankar wrote:Also, any moderator watching this thread, please move it to "Other JSE/JEE API" section.

Why? It sounds like it is about cron which is a UNIX tool.

Sagar Rohankar
Ranch Hand
Posts: 2907
1
Jeanne Boyarsky wrote:
Sagar Rohankar wrote:Also, any moderator watching this thread, please move it to "Other JSE/JEE API" section.

Why? It sounds like it is about cron which is a UNIX tool.

This is what the OP wrote:
sivachithambaram Rangaraj wrote:
i.e Trigger t=Triggerutils.makeHourlyTrigger(interval*24);'

and TriggerUtils is the Quartz class.