crontab(5)定义了以下字段:
field allowed values ----- -------------- minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sun, or use names)
并解释说:
Step values can be used in conjunction with ranges. Following a range with ``/<number>'' specifies skips of the number's value through the range. For example, ``0-23/2'' can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22'').
所以,就我的理解而言,没有双周刊的乔布斯。 我很确定有解决方法,你是什么? 还是我错过了什么?
每个星期三你都可以用cron来运行,然后让它决定是偶数周还是奇数周。 例如:
#!/bin/bash week=$(date +%U) if [ $(($week % 2)) == 0 ]; then echo even week else echo odd week fi
许多crons(你没有指定你正在使用的)支持范围。 所以像
0 0 1-7,15-21 * 3
会打到本月的第一个和第三个星期三。
对于cron的限制, Anacron是一个很好的解决方法。
周期延迟作业标识符命令
14 15 test.daily /path/to/script.sh
对于需要每隔一周运行一次的内容,请使用以下内容:
0 0 * * 5 [ `expr \`date +\%V\` \% 2` -eq 0 ] && echo "execute script"
这个特定的脚本预定在星期五运行。 要执行的一周可以通过使用“-eq 0”或“-eq 1”
如果你的需求不是每周两次,你可以简单的在本月的1号和15号运行cronjob:
15 8 1,15 * * /your/script.sh
其中每个月的第一天和第十五天上午8:15运行,无论一天的哪一天。
从这个解释设置3/2的星期应该在每隔一个星期三运行 – 它的隐含的,但我认为是可行的。