gpt4 book ai didi

linux - 特定日期和时间的 Cron 格式,每年仅运行一次

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:04:09 25 4
gpt4 key购买 nike

我必须安排 cron 在指定时间运行。我有如下命令。但是我无法理解如何在指定的日期和时间每年只运行一次。

我的问题是:第 5 个字段(星期几)的值应该是多少?

30 06 02 01 * bash -x /home/user/cron-specified-time.sh

时间/日期:1 月 2 日 06:30 AM - 一年只有一次

最佳答案

引自crontab(5)手册页:

The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the * character), 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.

因此,在您的情况下,因为您已经设置了月份中的某天,所以您可以将星期几保留为 *


或者,来自 POSIX spec (强调我的):

The specification of days can be made by two fields (day of the month and day of the week).

If month, day of month, and day of week are all <asterisk> characters, every day shall be matched.

If either the month or day of month is specified as an element or list, but the day of week is an <asterisk>, the month and day of month fields shall specify the days that match.

If both month and day of month are specified as an <asterisk>, but day of week is an element or list, then only the specified days of the week match.

Finally, if either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month, or the day of week, shall be matched.

关于linux - 特定日期和时间的 Cron 格式,每年仅运行一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48170895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com