What is meaning of this cron expression 0 50 13 1 1/1 ? *? - cronexpression

What does the following Cron expression mean?
0 50 13 1 1/1 ? *
0: means 0 seconds
50: means 50 minutes
13: means every 13 hours
But I don't know the meaning of 1 1/1 ? *.
Does the 1 mean "every day of the month"? Does the 1/1 mean each month of the year?

See the crontab(5) manual:
A line in a user crontab file has the form
minute hour day-of-month month day-of-week command
Your line:
0 50 13 1 1/1 ? *
Your interpretation does not make sense, as there is no "seconds" field. The "hour" field is "50". This literally means "At time 50:00 on the 13th of January, if it's a Monday, run the command '? *'".
If this is using CronTrigger from Oracle, or Quartz Enterprise Job Scheduler (which seems to be the same thing), the line means "At 13:50:00, on the 1st of every month, any day of the week, every year".
The 1 1/1 means "the 1st of every month (starting at January)". Had it been 1 1/2 it would have meant "the 1st of every second month (starting at January)".
The final ? * means "any day of the week, every year".

Related

Cron job one schedule for 3rd Sunday but different schedule every other day

We have jobs that are scheduled to run 1 time per day - every day
We do maintenance every 3rd Sunday of the month.
Up until now every month we have manually adjusted the cron to make the job run a little later in the morning then after maintenance we reset to the desired schedule
I am trying to change cron so that we
run at 7:00am every day EXCEPT the third Sunday of the month
run at 9:00am only on the third Sunday of the month
the second item I am able to handle
0 13 15-21 * 0
however, the first has me stumped. I thought this would do the job but it will only execute this if the day is between 1-14 or 22-31 but what if the 15th is not Sunday - then it won't run.
0 11 1-14,22-31 * *
How do I tell cron to run a schedule EXCEPT the third Sunday of the month?
There is a large base of guidance on how to limit when a cron runs to a specific window but I haven't found much for how to EXCLUDE a cron from a specific window
******** UPDATE ********
I think I may have come up with an answer - not sure if it is the most efficient but
0 11 1-14,22-31 * 0
0 13 15-21 * 0
0 11 1-14,22-31 * 1-6
The above will
run at 11:00 UTC on Sunday if date is between 1-14 or 22-31
run at 13:00 UTC on Sunday if date is between 15-21 (3rd Sunday)
run at 11:00 UTC Monday through Saturday all month
If a cron job has different timing than others, then it best to just define it by itself rather than trying to combine, unless you put some code in your script to do what you actually want. Doing something in cron on some nth day of the month is a pretty well known problem. Most crontab man pages have this note:
Note: The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the crent time. For example,
"30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
So it does OR between the day of the week and the day of the month, not an AND. I don't who ever thought this was helpful, but that's the way it is. You can see solutions at:
Run every 2nd and 4th Saturday of the month
you need something like (this assumes cron runs /bin/sh):
[ `date +\%w` -eq 6 ] && <command>
on your cron job line, the above is would restrict to running only on Saturday.

Hybris run a cron job 'x' days before month end

I want to create a cron job in Hybris that can run 5 days before the month end.I'm do some using
0 23 22-31 * * [ $(date -d +1day +%d) -eq 1 ]
What is equivalent to this in hybris cron job impex configuration.
hybris uses Quartz 2 as shown in the documentation.
From Quartz 2 documentation :
The ‘L’ character is allowed for the day-of-month and day-of-week fields. This character is short-hand for “last”, but it has different meaning in each of the two fields. For example, the value “L” in the day-of-month field means “the last day of the month” - day 31 for January, day 28 for February on non-leap years.[...] You can also specify an offset from the last day of the month, such as “L-3” which would mean the third-to-last day of the calendar month. When using the ‘L’ option, it is important not to specify lists, or ranges of values, as you’ll get confusing/unexpected results.
So you can use that 0 0 0 L-5 * ?.
Note: on older hybris version (v4) I'm not sure Quartz 2 was available. With Quartz 1 you can't use the L-x pattern.
If you want exactly 5 days before end of month you should create 3 triggers.
0 0 20 26 1,3,5,7,8,10,12 ? * -> the 26th at 20h for all 31 days month
0 0 20 25 4,6,9,11 ? * -> the 25th at 20h for all 30 days month
0 0 20 23 2 ? * -> the 23rd at 20h for february, this is actually a corner case because you may have different day for february...
There is also an other solution, but much more complex.
You can set a trigger for the first time it needs to run. Then in your job you can access a LocaleDate object to determine the next time the job should trigger. Finally update the trigger of the cronjob with Java code or impex creation+import.
I found better solution , using quartz
0 0 0 L-5 * ? *
ref

I need a specific Quartz cron expression

I need a cron expression that will fire every second day excluding weekends.
Example:
The schedule starts on Monday. The schedule continues in the following manner:
(1st week) Monday>Wednesday>Friday
(2nd week) Tuesday>Thursday
(3rd week) Monday>Wednesday>Friday
(4th week) Tuesday>Thursday
Is that possible using only cron? I know a solution would be to run it every day and when it runs on weekend 'manually' prevent it from running.
Maybe something like could help...
* * 1-31/2 * mon-fri command.sh
That means, "At every minute on every 2nd day-of-month from 1 through 31 and on every day-of-week from Monday through Friday."
https://crontab.guru/#__1-31/2_*_mon-fri
http://corntab.com/?c=__1-31/2_*_MON-FRI
(Didn't tried on real machine)
I will consider extended expression format so your query will looks like:
S M H DoM M DoW Y
0 0 10 1-31 * 1#1,3#1,5#1 *
This query can be understood as: Repeat at 10:00:00 every day of every month where day of week is (monday, wednesday, friday) and it's first week of month.
You would define such 4 queries (i'm considering that 1 in 1#3 is just monday and 3 is week number in month):
1.) 0 0 10 1-31 * 1#1,3#1,5#1 *
2.) 0 0 10 1-31 * 2#2,4#2 *
3.) 0 0 10 1-31 * 1#3,3#3,5#3 *
4.) 0 0 10 1-31 * 2#4,4#4 *
which runs the same command. But it won't work becouse of limitations of most of evaluators (as i guess).
If you are familiar with .NET, I made evaluator which handle such expressions correctly, but it's only evaluator so what you only receive are dates when your event should occur. There is no job sheduler integrated with it. Click

Cron zero'th of month

What would the zero'th of a month mean in the following scheduler?
never or every day?
shops.import.cron.expression=0 5 0 * * ?
i see that it is at 5:00 am but I can't find any definition of what the 0th of a month means.

Will crontab hour range a-b run after b too?

Say I have a crontab which runs every 20 minutes and I have a hour range which can vary so lets say a-b, which in one example could look like
*/20 5-23 * * * /usr/bin/cool_program
My question is, will the cron run at 23:00, 23:20, 23:40 and 00:00 too?
GK27's answer does not fully answer the question, so let me clarify:
cron will run jobs when the time matches the expression provided. Your expression tells it to run when the minute is divisible by 20 (*/20) and your hour range tells it to run when the hour is within the specified range inclusively (5-23). The remaining three * tell it to match any day, month, and any day of the week.
Therefore the first job will run at 05:00 because the hour, 05, is in the range 5 to 23 and the minute, 00, is divisible by 20. The last job will run at 23:40 because the hour, 23, is in the range 5 to 23 and the minute, 40, is divisible by 20. It will not run at 00:00 because the hour, 00, is not in the range 5 to 23.
#Alex's answer is correct, however it took me a while to find a source.
The answer is in man crontab.5 (or also info crontab) on Debian, Mac OS X, FreeBSD (and other Posix systems):
Ranges of numbers are allowed. Ranges are two numbers separated with
a hyphen. The specified range is inclusive. For example, 8-11 for
an ``hours'' entry specifies execution at hours 8, 9, 10 and 11.
For my application I wanted a script to run every 5 minutes during business hours (9am - 5pm) and another to run every 5 minutes outside of that. Unfortunately the ranges can't wrap across midnight, so you need to specify 3 ranges (morning, business hours, evening)
*/5 0-8,17-23 * * * outside-hours.sh
*/5 9-16 * * * business-hours.sh
This should run
outside-hours.sh first at 00:00 and finally at 08:55
business-hours.sh first at 09:00 and finally at 16:55
outside-hours.sh first at 17:00 and finally at 23:55
It will execute when minute is divisible by 20 and when hour is in 5-23 inclusive:
* 20 – every 20 minutes from 0 to 59
* 5-23 – 5 to 23 inclusive
* * – Every day
* * – Every month
* * - EvryDay of the Week
The first occurrence is 5:00 and the last 23:40
crontab.guru
Documentation for Reference

Resources