I need a cron job to run every second weekday for example
If cron job last ran on a Thursday it should run on the next Monday
The re-run on Wednesday and again on Friday again and on Tuesday and again on Thursday bring it back to the start.
Thanks
Run it every weekday, and have the script set a flag in a file that says whether it did the work the on the previous run. If it did, it skips the work that time and inverts the flag.
Related
I have written cronjobs in odoo12 and I want them to execute 6 days in a week with exemption of sundays since sunday is not a working day, how can i do that in odoo12/odoo11
You can do one thing run cron everyday but while executing the function you can skip there put condition there of not executing your function on sunday.
I was wondering if anyone knew how to create a cron job that runs from monday to friday at 6am.
I am using gitlab CI, quickly looked at the example syntax and am not exactly sure how to limit it to occur from monday to friday.
Not sure what about gitlab CI, but cron syntax is minute, hour, day of month, month, day of week, meaning job which should run every week day from 6am is
0 6 * * 1-5
I am trying to build a cron expression.
I need to execute a task every day of the week, from 5PM Monday to 5PM Friday, starting from 5PM Monday and every twelve hours until reaching 5PM Friday.
How can I do this?
Also, Is there a good tutorial to learn how cron expression are built?
Is there anyway to schedule cron jobs using whenever to run every two weeks, meaning first Saturday of the month and the third Saturday of the month.
How about the following:
require 'activesupport'
every :saturday do
month_day = Date.today.mday
if (1..7).include?(month_day) || (15..21).include?(month_day)
# YOUR TASK
end
end
I have cronjob to be run on every month first friday evening
i used the below mentioned entry
00 20 1-7 * Fri [ "$(date '+\%a')" = "Fri" ] && $HOME/path/to/my/script.sh > /dev/null 2>&1
This entry should run my script if Friday falls withing 1-7 day of the month, but my script is getting executed even after 7th (i.e on all Fridays of the month).
Please suggest how to fix it.
This is because when you specify a day of month and day of week, cron will execute the job when EITHER of those constraints are true. From the man page for crontab (5):
Note: The day of a command's execution can be specified by two fields —
day of month, and day of week. If both fields are restricted (i.e.,
aren't *), the command will be run when either field matches the cur‐
rent 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.
There isn't a direct way in cron to do what you want, but cron : how to schedule to run first Sunday of every month describes a workaround by using cron to run your script e.g. every Friday and then calculating in the script if the day of month is in the range 1-7, and only continuing when that is the case.
In response to the comment about using 5 rather than Fri to specify day of week: using Fri is OK, as the man page says:
Months or days of the week can be specified by name.