Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I want to create a cron job that runs every x weeks and on a specific weekdays.
for example: run every 2 weeks on midnight every Sunday and Monday.
the cron expression is stored for every "plan" and i use ncrontab function in SQL Server 2008 to generate the dates of given cron expression.
Is there an expression for it? or even join of several expressions?
I've tried to use the following expression, but it always gives the the same days in months
0 0 1/14 * *
2012-01-01 00:00:00.000
2012-01-15 00:00:00.000
2012-01-29 00:00:00.000
2012-02-01 00:00:00.000
2012-02-15 00:00:00.000
2012-02-29 00:00:00.000
EDIT:
I was looking for a recurrence of every x days/weeks and the main problem with cron, is that it resets the recurrence to the first day of month every time.
for example, if i start the recurrence on 29th for every 3 days, the next occurrence will be the 1st day of next month.
I've neglected cron for the next solution:
http://www.codeproject.com/Articles/20343/Recurring-Date-Generator-with-Pattern-Coding
try 0 0 * * 0/2,1/2
0 and 1 are Sunday and Monday, and /2 is 'every other'
EDIT:
After more research into cron, the above is incorrect because /2 indicates the step (every other value), so 0/2 is equivalent to 0,2,4,6, and 0/2,1/2 is equivalent to 0,1,2,3,4,5,6,7 which explains why you saw it interpreted as every single day of the week.
In your example above 1/14 means starting with 1st of the month, increment by 14, yielding 1,15,29
That being said, if this were for a *nix crontab, then you could've been more granular about the schedule by having something like 0 0 * * Sun,Mon check_if_should_run.sh && the_script_to_run.sh. Using Ncrontab, I can't think of a way to set up every-other-week scenario.
Related
This question already has answers here:
Cron job every three days
(12 answers)
Closed last month.
please i want to create crontab that should runs evry 14th working day at 10am.
Im tried this row but still not giving what i want.
0 10 14 * 1-5
Thank you in advance
This will make it run on the 14th of the month (if that day falls between monday and friday)
0 10 */14 * 1-5
If you want it to run every 14 working days, you might want the cron job to call a script. Tell cron to run every day at 10. The script can then keep track of last time it ran, compare it and run if it's been 14 days and if today is a weekday.
I want to create a reminder very similar to google calendar custom reminder feature.
Where user can select number of days/weeks/months/years using djano-celery periodic task and crontab.
For eg I want a task to run on every 26th May in every 2 years what can be the expression.
After research I found the below expression but it is not working.
58 10 26 5/24 *
For this i am getting the below result in crontab generator
Similarly I want a task to run on every Thursday and Friday which repeats in every 2 weeks.
As per my research it should be like
30 10 */14 * 4,5
But this as well is not working.
I want django-celery-crontab expression.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
Is there anyway to make a cronjob run every hour just on Mondays , every week.
* * * * 1
stands for At every minute on Monday. But I am looking for similar thing for every hour on Mondays.
Thanks,
Cron expression would look like with explaination:
min hour day(month) month day(week)
0 0-23 * * 1
* any value
, value list separator
- range of values
/ step values
“At minute 0 past every hour from 0 through 23 on Monday.”
0 0-23 * * mon
You can use the above. This will schedule your job to run at minute 0 past every hour from 0 through 23 on Monday.
This means:
at 2018-05-07 00:00:00
at 2018-05-07 01:00:00
at 2018-05-07 02:00:00
at 2018-05-07 03:00:00
at 2018-05-07 04:00:00 and so on.
Hope this helps!
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I need to run a bash script every day using a cron job. For a sake of example let's say it will print Hello world but only on a certain condition. If it's the 14 of the month or the last day of the month. But if the 14th or the last day of the month falls on a Saturday or Sunday it should then instead print on the Friday before that Saturday or Sunday.
For example this month's (July 2016) last day of the month is the 31st (a Sunday), this script should print Hello world on July 29th since the last day of the month falls on a Sunday
You can put a regular call in cron and what's beyond cron's possibilities in the script itself to exit if it shouldn't go or whatever. I don't know if that's a good practice, but it's a solution.
Why not set up a [ cron job ] ?
# m h dom mon dow command
* 16 1-15 * 1-5 /path/to/bakupscrtipt
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a form where user chooses when to run a script. I've fields {time,day of week, first/last}. Now when the user chooses for example: 10:45 AM every first Monday - Which means run script on every first Monday of every month, how can I convert this to cron job.
Thanks.
Unfortunately, the day-of-month and day-of-week fields in a crontab entry are ORed together rather than ANDed. So you can't really do a "first Monday of the month" with crontab fields alone; you need additional logic. You could do something like this:
min hr 1-7 * * [ `date +%w` -eq 1 ] && first-monday.sh
Finding the last instance of a weekday is a bit trickier since it depends on how many days are in the month:
min hr 25-31 1,3,5,7,8,10,12 * [ `date +%w` -eq 5 ] && last-friday.sh
min hr 24-30 4,6,9,11 * [ `date +%w` -eq 5 ] && last-friday.sh
min hr 22-28 2 * [ `date +%w` -eq 5 ] && last-friday.sh
On leap years in which February 29th falls on Friday, that last entry will actually run the script on the 22nd instead, but since cron jobs can't specify a year, that's about as close as you can get.