Cron作业每x周和在特定日期运行 [英] Cron job run every x weeks and on specific days

查看:177
本文介绍了Cron作业每x周和在特定日期运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个cron作业,每隔x周和在特定的工作日运行。
例如:在每个星期日和星期一午夜运行每2周。

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.

cron表达式存储每个计划,我使用 ncrontab 函数在SQL Server 2008中生成给定cron表达式的日期。

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

编辑:

I正在寻找每x天/周的复发和cron的主要问题是它每次将复发重置为每月的第一天。
例如,如果我每3天在第29天开始重复,下一个发生将是下个月的第一天。


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.

我忽略了cron为下一个解决方案:
http://www.codeproject。 com / Articles / 20343 / Recurring-Date-Generator-with-Pattern-Coding

I've neglected cron for the next solution: http://www.codeproject.com/Articles/20343/Recurring-Date-Generator-with-Pattern-Coding

推荐答案

$ c> 0 0 * * 0 / 2,1 / 2

try 0 0 * * 0/2,1/2

0 1 是星期日和星期一, / 2 是每隔一个

0 and 1 are Sunday and Monday, and /2 is 'every other'

编辑:

经过对cron的更多研究,上述是不正确的,因为 / 2 表示步骤(每隔一个值),因此 0/2 等效于 0,2,4,6 0 / 2,1 / 2 等效于 0,1,2,3,4,5,6,

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.

在上面的例子中 1 /

In your example above 1/14 means starting with 1st of the month, increment by 14, yielding 1,15,29

也就是说,如果这是一个* nix crontab,那么你可以通过使用 0 0 * * Sun,Mon check_if_should_run.sh& & the_script_to_run.sh 。使用Ncrontab,我不能想办法设置每隔一周的情况。

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.

这篇关于Cron作业每x周和在特定日期运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆