指定“所有奇数值"在 crontab 中? [英] Specifying "all odd values" in crontab?

查看:12
本文介绍了指定“所有奇数值"在 crontab 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 crontab 中,我可以使用星号表示每个值,或使用*/2"表示每个偶数值.

In crontab, I can use an asterisk to mean every value, or "*/2" to mean every even value.

有没有办法指定每个奇数值?(像1+*/2"这样的东西会起作用吗?)

Is there a way to specify every odd value? (Would something like "1+*/2" work?)

推荐答案

根据您的 cron 版本,您应该能够做到(比如几个小时):

Depending on your version of cron, you should be able to do (for hours, say):

   1-23/2

通过 crontab(5) 联机帮助页中的 EXTENSIONS 部分:

Going by the EXTENSIONS section in the crontab(5) manpage:

   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

但是将您的命令包装在一个 shell 脚本中可能更容易,如果它在奇数分钟内没有被调用,它将立即退出.

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.

这篇关于指定“所有奇数值"在 crontab 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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