How to set cron job for bi-weekly (twice a week) - linux

How do I set a cron job to run twice a week?
I know how to set a cron job for every week:
0 0 * * 0

How about the following:
0 0 * * 1,4
This sets the day of week to Monday (1) and Thursday (4). You can choose any values 0–7 (both 0 and 7 are Sunday).
For a more readable crontab, you can also use names:
0 0 * * MON,THU
See also: How to instruct cron to execute a job every second week?

In reply to Elby question :
0 0 1,15 * *
This will set cronjob for (fortnight) 2 times in a Month i.e 1st day and 15th day of a month.

These answers are great, but I wanted to share a tool I found right after looking at this question and answers called crontab.guru. I'm not affiliated, I just thought it was a nice tool.
crontab.guru for 'At 00:00 on Monday and Thursday.'

Related

What is Azure functions Cron Expression to trigger on 2nd Sunday of every month?

I have Timer Trigger Azure function, which I want to trigger on 2nd Sunday of every month. what should be the cron expression for it?
I have tried below ones but it's showing as wrong format of cron expression
0 0 0 ? * 7#2
0 0 0 ? * SUN#2
The second Sunday of the month falls on one (and only one) of the dates from the 8th to the 14th inclusive. Then the cron expression will be easy to get it.
Suppose it should be 0 0 0 8-14 * Sun and the below is my test, it shows the first five date.
From the picture suppose the expression should be right, hope this could help you.

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.)

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

How to set a Cron job in Every two hour from 10-19

I had a question before 1 month regarding this. that was the interval of 1 hour and i got exact answer. below is the link to the old question
How to set a Cron job in Every one hour from 9:00 am to 6:00 pm ( Monday to Friday )
Thank you Stack Over Flow and the contributor Andy Holmes
Now I got a new requirement on Cron expression, the same way i need it in every 2 hour.
I have tried
0 9/2-18/2 * * 1-5
and
0 (9-18)/2 * * 1-5
But that doesn't help, Please help me
Use:
0 10-18/2 * * 1-5
You specify the hour range 9-18 and then /2 to mean step by 2 hours. The man page explains this pretty clearly:
Step values can be used in conjunction with ranges. Following a range with /<number> specifies skips of the number's value through the range. For example, 0-23/2 can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is 0,2,4,6,8,10,12,14,16,18,20,22). Steps are also permitted after an asterisk, so if you want to say "every two hours", just use */2.
If your interface doesn't allow this shorthand, you have to list them out by hand:
0 10,12,14,16,18 * * 1-5

can't get the right cron job timing

i'm trying to do some stuff automatically every 8 Weeks, so i had open a new user crontab like this one:
crontab -e
0 9 * */2 1-5 do_this_stuff
# do it every 2 month on monday till friday at 9:00 am
This should do the job every 2 month on monday till friday on 9:00 am, but i does not. It is doing the job evey week once. Don't get it. What i'm doing wrong?
Running System is a latest debian.
regarding http://wiki.ubuntuusers.de/Cron it should run fine
The Anwer is, cron can't do a job randomly on a random day in a month. I had to change my crontab to: 0 9 1 */2 * do_sm_stuff -- this runs every two Month always on the first Day in a Month
thank you Igor

Resources