how to build cron expression for hours and minutes - cron

i want a cron expression for a schedule which runs for every 2hr 10 min and output am expecting is
2:00
4:10
6:20
i tried 0 0/2 0/2 * * ? for that and the output was like this
Thursday, November 1, 2012 12:50 PM
Thursday, November 1, 2012 12:52 PM
Thursday, November 1, 2012 12:54 PM
source-http://www.cronmaker.com
Thanks in advance..

I too had searched a lot previous to run a cron for every (> 60 ) minutes, but was not able to find any solution.
Best way to implement the solution to your problem, is to write your own script that would check the script's last run which you can handle in any way (check timestamp, log the last run somewhere, etc) and would run the required job if only the time conditions are met.
Then put a cron to call this wrapper script every 10 mins (in your case), as this would ensure, it would get checked for each of the time you would have expected the original final job to run.
Hope this helps.

Related

Cron Scheduler - every quarter end third Sunday # 3:30 AM CST

Actually I am trying to schedule an application , which has to be run at
Cron expression to run application job for every end of quarter on 3rd Sunday at 3:30 AM CST
currently am using 0 */10 * ? * * - which runs for every ten minutes.
when I search on online ,this link https://crontab.guru/every-quarter
0 0 1 */3 * this would run for every quarter I guess.
But for my requirement , which I stated above, am not sure actually.
but , i referred some of the previous questions and some trial and error , I reached something like this 30 3 15-21 */3 SUN but am not sure. Please give your thoughts
OK .. for spring scheduler cron expression, below is my best bet
0 30 03 15-21 3,6,9,12 SUN
should work i think. tested partially. since, the above expression will run only on june.

Scheduling Airflow DAG at two differents times per day

I want to launch a same DAG at 2 differents times in the same day without copying this one, for exemple I want to run it every day at 5:00 PM and 6:30 PM
I'm not super certain if it will work but you might want to try passing a cron string to the schedule argument of the DAG. Where the cron defines your two times.
I'm also not certain you'll be able to have 5:00 and 6:30 only though, as different minute / hours.
This is a handy site for validating cron expressions.
This means running at hours 5 and 6 at minute 30.
A problem would be if you wanna 5:00 and 6:30, I don't guess CRON does not handle such options

Cron Expression - Start at 10:20 and execute each 10min until 19:00

I have a case in which I'm migrating some tasks from Windows to a platform and we are using cron expressions to replace the Windows Scheduler.
Today we have something in Windows like At 10:20 AM every weekday, every 10 minutes for 9 hours. I'm trying to replace it with chron but I couldn't achieve it so far.
The closest I got is 0 20/10 10-19 * * MON-FRI. The thing is on this cron, it won't execute at 11:00, 12:00 and so on. We have a specific case in which we don't want it to execute at 10:00 AM.
The only option I found is to execute at 10:00AM and put some condition to validate it. Is it possible to achieve this result with only chron?
Thanks!
You can do it with cron, but you'll need to break it up into two schedules.
20/10 10 * * MON-FRI
and
*/10 11-19 * * MON-FRI
Btw, if this is cron on unix, there is no field for seconds.

Azure WebJob/Scheduler every 30 minutes from 8am-6pm?

When I go to configure a Schedule in the Azure management console, I'm only given the option of scheduling with an absolute end date/time (or never ending) and an interval.
So I can't, from this UI, schedule a job to every 30 minutes run every day from 8:00 AM to 6:00 PM only (i.e. don't run from 6:01 PM to 7:59 AM). Windows Task Manager and all other schedulers (cron, quartz) I've used before support the behaviour I want.
Is type of schedule supported at all in Azure, e.g. through the API or a hackish use of the Portal HTTP/JSON interfaces?
You can use the built-in scheduling which is more flexible than the Azure one.
You can learn more about how that works from this blog post http://blog.amitapple.com/post/2015/06/scheduling-azure-webjobs/
The summary: create a file called settings.job that contains the following piece of json
{"schedule": "cron expression for the schedule"}
in your case the cron expression for "every 30 minutes from 8am to 6pm" would be 0,30 8-18 * * *
so the JSON you want is
{"schedule": "0,30 8-18 * * *"}
Keep in mind that this uses the timezone of the machine, which is UTC by default.
This is something you need to implement in your WebJob. I have a similar issue in that I have WebJobs with complex schedules. Fortunately it isn't hard to implement.
This snippit gets your local time (Eastern from what I can tell) from UTC which everything is Azure is set to. It then checks if it is Saturday or Sunday and if it is exits out (not sure if you need this). It then checks whether it is before 8AM or after 6PM and if it is exits out. If it passes both those conditions the WebJob runs.
//Get current time, adjust 4 hours to convert UTC to Eastern Time
DateTime dt = DateTime.Now.AddHours(-4);
//This job should only run Monday - Friday from 8am to 6pm Eastern Time.
if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday) return;
if (dt.Hour < 8 || dt.Hour > 16) return;
//Go run WebJob
Hope this helps.

Quartz Cron expression with custom hours

I want to write a quartz cron expression that will fire my trigger in the following times:
7:40 AM, 1 PM, 6 PM.
I know that I can do this:
0 0,40 7,13,18 ? * 2-6 (to run it MON - FRI every day in the month)
But the problem is that it will actually run at 7:00, 7:40, 13:00, 13:40, 18:00, 18:30.
Please show me a best practice to such issue.
Thanks,
Steve

Resources