I'm looking for a way to create a cron job which should be run every 2 days. I mean it should run on the August 16, August 18, August 20, August 22, August 24, August 26, August 28 and so on. Note that today is August 14.
I have tried several scripts including 0 0 */2 * * myscript.php.
It turns out that 0 0 */2 * * myscript.php only run execute every 2nd day of every month according to http://cronchecker.net/. This is obviously NOT what I'm looking for.
Any idea please? Thanks
You can try the following
0 0 2-30/2 * * myscript.php
This should work for you, as it runs every even day of the month
Related
This is more difficult than I thought. In the month of September 2022, I need cronjobs to run on the 1st, 3rd and 5th Thursdays (there are 5 Thursdays this month!), but in October 2022 I need them to run on the 2nd and 4th Thursdays.
I would like my tasks to run every 2 weeks without skipping any days when a month has 5 Thursdays
How can I accomplish something like this with a cronjob? Is it even possible?
You can do cron on odd/even week of month.
#Every day except Thursday at 1am
0 1 * * 0,1,2,3,5,6 yourCommand
#Every Thursdays at 1am, proceeds only on even weeks
0 1 * * 4 test $((10#$(date +\%W)\%2)) -eq 0 && yourCommand
#Every Thursdays at 6am, proceeds only on odd weeks
0 6 * * 4 test $((10#$(date +\%W)\%2)) -eq 1 && yourCommand
If you want more info regarding this please go this reference link :
cron_info
I have a Rundeck job that I would like to schedule to run from Sunday at 10 am to Friday at 17:00.
I could create three separate instances of the job and schedule it as below:
#every Sunday starting at 10 until midnight
0 */15 10-23 ? * 1
# every fifteen minutes starting on Monday midnight to Thursday 11:59 am
0 */15 * ? * 2-5 *
#every Friday starting at 12 am until 17:00 pm
0 */15 00-17 ? * 6
But it seems like there has to be a better way that will allow me to do this in one job. Any ideas? Thanks in advance.
The easiest way to do that is with Calendars feature (Enterprise), you can assign each rule to a single job. Take a look at this.
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
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
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