How to schedule job on Oozie every exactly n day regardless of the month - cron

I would like to schedule a job to run every n day where n is not 1 or 7. I know the syntax 0 0 */n * *, but when I check for the next execution dates, it always runs on 1st of the next month, regardless of the n day interval from the last month's run. Hence, the interval is not exactly n days. How can I properly schedule this case?
Here is the example of this problem where it will execute two days consecutively if it the date is near the end of the month.

Related

Scheduling job every other day in Azure Databricks

I need to schedule a job which will run every other day(if start is Mon then Wed, Fri, Sunday...).
But in databricks job scheduler options are only for day, week, month and yearly basis.
You just need to specify schedule as cron expression instead of using UI options. Databricks jobs are using Quartz syntax, so for your case expression will look as following (fill seconds/minutes/hours for time when you need to start jobs):
seconds minutes hours * * 1,3,5,7
The cron trigger expression consists of 6 fields separated by a space:
Seconds (0 -59)
minute (0 -59)
Hour (0 - 23)
Day of the month (1-31)
Month (1-12)
Day of the week (0-6, 0 = Sunday)
Year (optional, default is current year)
For the given schedule, the expression would be:
0 0 0 1/2 * ?
This means that the schedule will run at midnight (0th min and 0th hour) every other day (/2 in the third field). The 4th and 5th fields are not relevant so they are set to a wildcard ().
To summarize, this schedule will run every other day at 12.00 AM
I have tried the following schedule in databricks and it accepts the cron as valid schedule. you can also try the following cron along with #alex-ott's answer.
seconds minutes hours ? * 1,3,5,7
As you are specifying the day of the week, your day of the month should be ?.

How to create a cron schedule for every 3 weeks starting from today or X date

I'm needing to create a cron schedule for a Jira subscription to email out every 3 weeks from x date to line up with our sprints.
I could manually trigger this but ideally would like this automated.
-edited for current cron
0 0 8 1/21 * ? * this is as close as I've gotten but will only trigger on the 1rst of every month then 21 days after.

Cron expression for 24 hour period

I'm trying to write a crontab expression that will begin a specified period of time and run on an interval for a 24 hour period. For example I want the job to run every Thursday beginning at 4 PM and repeat every hour for 1 day. Is there a way to do this? Everything I have tried stops at the end of the day Thursday.
You need two crontab entries, one for the occurrences on Thursday and one for the occurrences on Friday.
For example (I have not tested this):
0 16-23 * * 4 your_command
0 0-15 * * 5 your_command
The fifth column is the day of the week, with Sunday=0. (Vixie cron also lets you specify the day of the week by name.)

CRON Expression for All Mondays in a month except first one

I'm trying to come up with a CRON expression that will allow me to schedule a quartz trigger to run on every Monday in a month except the first one.
References:
http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html
https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm
CRON allows you to specify the nth occurrence of a day of the week easily. An expression for First Monday of the month would be:
0 5 0 ? * 2#1
Where the 2#1 represents the first Monday of the month (2 = day of the week, 1 being the nth occurrence)
However, if I try to do something like
0 5 0 ? * 2#2-2#5
OR
0 5 0 ? * 2#2,2#3,2#4,2#5
It complains with the message
Support for specifying multiple "nth" days is not implemented.
Does anyone know how to achieve this in CRON?
Where cron doesn't give you the expressiveness you desire(a), it's a simple matter to change the command itself to only execute under certain conditions.
For your particular case, you know that the first Monday of a month is between the first and seventh inclusive and subsequent Mondays must be on the eighth or later.
So use cron to select all Mondays but slightly modify the command to exclude the first one in the month:
# mm hh dom mon dow command
0 1 * * 1 [[ $(date +%u) -gt 7 ]] && doSomething
That job will run at 1am every Monday but the actual payload doSomething will only be executed if the day of the month is greater than seven.
Some people often opt for putting the test into the script itself (assuming it even is a script) but I'm not a big fan of that, preferring to keep all scheduling information in the crontab file itself.
(a) Don't be mistaken into thinking you can combine the day of week 1 and day of month 8-31 to do this. As per the man page, those conditions are OR'ed (meaning either will allow the job to run):
Commands are executed by cron when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time
Combining those two will run the job on the first Monday and every single day from the eighth onwards.

cron expression every 2 days not making sense for monday

i have a cron expression-
0 0 12 */2 * ?
If start date is monday and time is 11:40 am, the next trigger date i'm expecting is monday 12:00, followed by wednesday, friday,etc.
But when i give this expression, the first trigger is set to tuesday 12:00, followed by thursday, saturday,etc
i verified this on http://cronmaker.com
Why does this behavior occur for monday?
If the start date is set to any other day it seems to behave the way its supposed to.
So if it was set on Tuesday 11:50 am , the first trigger is on tuesday 12:00.
Please help me understand. Is it a bug or expected behavior? Is there a work around to make it trigger on monday?
Thanks
Your cron schedule doesn't care about the day of the week. It is running simply on every uneven day of the month. This is the expected behaviour.
If you need it to run on Mondays, you should use something like 0 0 12 ? * MON,WED,FRI
First of all you expression only uses ? for the day of the week, so effectively you are not controlling that part.
Second the / character in a Cron expression indicates an increment. And when used next to a *, the star just means the lower bound for that value, 1 for the day of the month.
So indeed you are asking for a fire at noon every uneven day of the month. And the start time of the trigger will only constrain the first instance to be the next uneven day of the month.
You cannot express what you seem to desire with a cron trigger - that is a schedule which is based off the start time of the trigger. You should use s SimpleTrigger for this

Resources