作者:历史本轻狂 | 来源:互联网 | 2023-02-06 15:48
Incrontab,Icanuseanasterisktomeaneveryvalue,or*2tomeaneveryevenvalue.在crontab中,
In crontab, I can use an asterisk to mean every value, or "*/2" to mean every even value.
在crontab中,我可以使用星号表示每个值,或“* / 2”表示每个偶数值。
Is there a way to specify every odd value? (Would something like "1+*/2" work?)
有没有办法指定每个奇数值? (像“1 + * / 2”这样的东西有用吗?)
5 个解决方案
79
Depending on your version of cron, you should be able to do (for hours, say):
根据你的cron版本,你应该可以做(几小时,比如说):
1-23/2
Going by the EXTENSIONS section in the crontab(5) manpage:
通过crontab(5)联机帮助页中的EXTENSIONS部分:
Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".
For a more portable solution, I suspect you just have to use the simple list:
对于更便携的解决方案,我怀疑您只需使用简单列表:
1,3,5,7,9,11,13,15,17,19,21,23
But it might be easier to wrap your command in a shell script that will immediately exit if it's not called in an odd minute.
但是将命令包装在一个shell脚本中会更容易,如果在一个奇怪的分钟内没有调用它,它将立即退出。