Cron表达式格式:`*` 和 `?`

3

我刚刚阅读了关于Cron表达式格式的这篇文章

The ? Character

The question mark (?) character can be used only in the `dayofmonth` and `dayofweek` fields, but not at the same time. You can think of the `?` character as "I don't care what value is in this field." This is different from the asterisk, which indicates every value for the field. The `?` character says that no value was specified for this field.

The reasons a value can't be specified for both fields are tough to explain and even tougher to understand. Basically, if a value was specified for each, the meaning would become ambiguous: Consider if an expression had the value 11 in a field for the day of the month and a value of WED in the field for the day of the week. Should that trigger fire only on the 11th of the month if it falls on a Wednesday? Or should it fire on both the 11th and every Wednesday? The ambiguity is removed by not allowing a value in both fields at the same time.

Just remember that if you specify a value in one of the two fields, you must put a ? in the other.

Example expression:

0 10,44 14 ? 3 WED

我想知道如何创建一个定时任务,让它在每个13号星期五执行某些操作(例如格式化数据分区),或者在14号星期六执行其他操作(例如创建新的备份)。


这里有一个关于Cron表达式的好解释:https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm - deebs
从上面的链接中,我相信表达式应该是 0 0 12 13 * 5(这应该是每个月的第13天(13)的星期五(5),中午(12)(0)(0))。但我刚开始学习这些东西! - deebs
回到这个问题上来... NCron 表达式是:0 0 12 13 * F。https://ncrontab.swimburger.net/ - deebs
1个回答

0
##########################################################
#        minute (0-59),
#        hour (0-23),
#        day of the month (1-31),
#        month of the year (1-12),
#        day of the week (0-6 with 0=Sunday).
##########################################################
# this is friday the 13th at 0:00 i guess?
# daynr:13 and dayname: friday 
0 0 13 * 4 /script.cgi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接