Crontab /每月第一个星期日运行cronjob [英] Crontab / Running cronjob on first sunday in month

查看:789
本文介绍了Crontab /每月第一个星期日运行cronjob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我想在每月的每个第一个星期日的上午7点执行php脚本。我在服务器crontab中输入了以下行。

I want to execute a php script on every first sunday in month at 7 am . I entered the following line in the servers crontab.

0 7 1-7 * 0      user /path/to/script.php

今天我看到脚本确实在星期三早上运行。怎么会这样我以为最后一个 0 定义了星期天?

Today I saw that the script did run on wednesday morning. How could that happen? I thought that the last 0 defines sunday?

感谢您的高级帮助。

推荐答案

从手册页:


命令由执行cron(8),当分钟,小时,
和年份中的月份字段与当前时间匹配时,并且当
中的至少一个与两天字段(月份中的日期或星期几)匹配时,当前
时间(请参阅下面的``注释'')。

Commands are executed by cron(8) when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) matches the current time (see ``Note'' below).

及更高版本:


注意:可以通过两个字段指定命令执行的日期-每月
和星期几。如果两个字段都受限制(即
不是*),则当任一字段与当前
时间匹配时,将运行该命令。例如, 30 4 1,15 * 5将导致一个命令在每个月的1号和15号以及每个星期五的凌晨
运行。

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 (ie, are not *), the command will be run when either field matches the current 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.

换句话说,您的脚本在1号到7号以及任何星期日运行。

In other words, your script runs on the 1st through the 7th as well as any Sunday.

这篇关于Crontab /每月第一个星期日运行cronjob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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