计划在每月的第一、第二和第三个星期二运行cron作业
我想得到一些帮助,为我的三个脚本设置cron时间表。我需要安排第一个脚本在每个月的第一个星期二运行,第二个脚本在每个月的第二个星期二运行,第三个脚本在每个月的第三个星期二运行。这是我到目前为止所拥有的计划在每月的第一、第二和第三个星期二运行cron作业,cron,crontab,Cron,Crontab,我想得到一些帮助,为我的三个脚本设置cron时间表。我需要安排第一个脚本在每个月的第一个星期二运行,第二个脚本在每个月的第二个星期二运行,第三个脚本在每个月的第三个星期二运行。这是我到目前为止所拥有的 # Run first script on the 1st Tuesday of every month at 9:00 AM 0 9 1,2,3,4,5,6,7 * 2 wget -q -O /dev/null http://site.com/first-script # Run second
# Run first script on the 1st Tuesday of every month at 9:00 AM
0 9 1,2,3,4,5,6,7 * 2 wget -q -O /dev/null http://site.com/first-script
# Run second script on the 2nd Tuesday of every month at 9:00 AM
0 9 8,9,10,11,12,13,14 * 2 wget -q -O /dev/null http://site.com/second-script
# Run third script on the 3rd Tuesday of every month at 7:00 AM
0 7 15,16,17,18,19,20,21 * 2 wget -q -O /dev/null http://site.com/third-script
我相信这些脚本将在每个月的第一、第二和第三个星期二运行,并在每个月的第1-21天运行。从我所读到的来看,一周中的每一天都是一天,这是真的吗
希望这是可能的w/cron,否则我将不得不决定是否在脚本本身内部运行脚本。另一种选择是创建主脚本以在每个星期二运行,验证星期二是,并且小时是相应地调用适当的辅助脚本
0 7,9 * * 2 wget -q -O /dev/null http://site.com/main-script
我希望这会有帮助
问候。另一种方法是创建主脚本以在每个星期二运行,验证星期二是否正确,小时是否正确,并相应地调用相应的辅助脚本
0 7,9 * * 2 wget -q -O /dev/null http://site.com/main-script
我希望这会有帮助
问候。他们是OR
它将在每周二和列出的日期运行。它们是OR
它将在每周二和列出的日期运行。您可以将cron设置为: 00 09 1-7,8-14,15-21*2/path/myscript
这将在第一、第二和第三个星期二上午9点运行脚本。您可以将cron设置为: 00 09 1-7,8-14,15-21*2/path/myscript
这将在第一、第二和第三个星期二的上午9点运行脚本。如果不想将日期检查逻辑直接放入脚本中,可以让cron job shell命令部分在执行脚本之前检查一周中的某一天
# Run first script on the 1st Tuesday of every month at 9:00 AM
0 9 1-7 * * [ "$(date '+\%a')" = "Tue" ] && wget -q -O /dev/null http://example.com/first-script
# Run second script on the 2nd Tuesday of every month at 9:00 AM
0 9 8-14 * * [ "$(date '+\%a')" = "Tue" ] && wget -q -O /dev/null http://example.com/second-script
# Run third script on the 3rd Tuesday of every month at 7:00 AM
0 7 15-21 * * [ "$(date '+\%a')" = "Tue" ] && wget -q -O /dev/null http://example.com/third-script
如果[$(日期'+\%a')”=“Tue”]条件成功,脚本将执行。必须用反斜杠转义%符号,因为cron将%视为特殊字符
因为一周有7天,所以一个月的第一个星期二保证在1-7范围内,第二个在8-14范围内,第三个在15-21范围内
要捕获第一个星期二,您不能执行以下操作:
0 9 1-7 * 2 && wget -q -O /dev/null http://example.com/some-script
…因为1-7(月日)和2(周日)实际上将是或。由于某种原因,Cron对这两个字段的处理方式与其他字段不同。在上面的示例中,您的脚本每天都会在1-7范围内运行,和每周二运行一次。如果您不想将日期检查逻辑直接放入脚本中,您可以使用Cron作业shell命令在执行脚本之前,检查一周中的某一天是否有条件
# Run first script on the 1st Tuesday of every month at 9:00 AM
0 9 1-7 * * [ "$(date '+\%a')" = "Tue" ] && wget -q -O /dev/null http://example.com/first-script
# Run second script on the 2nd Tuesday of every month at 9:00 AM
0 9 8-14 * * [ "$(date '+\%a')" = "Tue" ] && wget -q -O /dev/null http://example.com/second-script
# Run third script on the 3rd Tuesday of every month at 7:00 AM
0 7 15-21 * * [ "$(date '+\%a')" = "Tue" ] && wget -q -O /dev/null http://example.com/third-script
如果[$(日期'+\%a')”=“Tue”]条件成功,则将执行脚本。%符号必须用反斜杠转义,因为cron将%视为特殊字符
因为一周有7天,所以一个月的第一个星期二保证在1-7范围内,第二个在8-14范围内,第三个在15-21范围内
要捕获第一个星期二,您不能执行以下操作:
0 9 1-7 * 2 && wget -q -O /dev/null http://example.com/some-script
…因为1-7(月日)和2(周日)实际上是或'd。由于某些原因,Cron对这两个字段的处理方式与其他字段不同。在上面的示例中,您的脚本每天都会在1-7范围内运行,和每周二运行。很酷,谢谢。我想我会将逻辑转移到PHP主脚本中,确定每个月的哪个星期二,并按照您的建议,简单地安排每个星期二运行一个cron。谢谢很好,谢谢。我想我会将逻辑转移到PHP主脚本中,确定每个月的哪个星期二,并按照您的建议,简单地安排每个星期二运行一个cron。谢谢