Linux 我如何获得每 30 分钟运行一次的 cron 作业?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/584770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How would I get a cron job to run every 30 minutes?
提问by Darryl Hein
I'm looking to add a crontab
entry to execute a script every 30 minutes, on the hour and 30 minutes past the hour or something close. I have the following, but it doesn't seem to run on 0.
我希望添加一个crontab
条目以每 30 分钟、每小时和 30 分钟或接近的时间执行一次脚本。我有以下内容,但它似乎没有在 0 上运行。
*/30 * * * *
What string do I need to use?
我需要使用什么字符串?
The cron is running on OSX.
cron 在 OSX 上运行。
采纳答案by vladr
Do:
做:
0,30 * * * * your_command
回答by Eddie
Try this:
尝试这个:
0,30 * * * * your command goes here
According to the official Mac OS X crontab(5) manpage, the /
syntax is supported. Thus, to figure out why it wasn't working for you, you'll need to look at the logs for cron. In those logs, you shouldfind a clear failure message.
根据官方的 Mac OS X crontab(5) manpage,/
支持语法。因此,要弄清楚为什么它对您不起作用,您需要查看 cron 的日志。在这些日志中,您应该会找到一条明确的失败消息。
Note: Mac OS X appears to use Vixie Cron, the same as Linux and the BSDs.
注意:Mac OS X 似乎使用 Vixie Cron,与 Linux 和 BSD 相同。
回答by Allyn
回答by PCheese
If your cron job is running on Mac OS X only, you may want to use launchd instead.
如果您的 cron 作业仅在 Mac OS X 上运行,您可能需要使用 launchd。
From Scheduling Timed Jobs (official Apple docs):
Note: Although it is still supported, cron is not a recommended solution. It has been deprecated in favor of launchd.
注意:虽然它仍然受支持,但 cron 不是推荐的解决方案。它已被弃用,取而代之的是 launchd。
You can find additional information (such as the launchd Wikipedia page) with a simple web search.
您可以通过简单的网络搜索找到其他信息(例如启动的 Wikipedia 页面)。
回答by aequalsb
crontab does not understand "intervals", it only understands "schedule"
crontab 不理解“间隔”,它只理解“调度”
valid hours: 0-23 -- valid minutes: 0-59
有效小时数:0-23 -- 有效分钟数:0-59
example #1
示例#1
30 * * * * your_command
30 * * * * your_command
this means "run when the minute of each hour is 30" (would run at: 1:30, 2:30, 3:30, etc)
这意味着“在每小时的分钟为 30 时运行”(将在:1:30、2:30、3:30 等运行)
example #2
示例#2
*/30 * * * * your_command
*/30 * * * * your_command
this means "run when the minute of each hour is evenly divisible by 30" (would run at: 1:30, 2:00, 2:30, 3:00, etc)
这意味着“当每小时的分钟被 30 整除时运行”(将在:1:30、2:00、2:30、3:00 等运行)
example #3
示例#3
0,30 * * * * your_command
0,30 * * * * your_command
this means "run when the minute of each hour is 0 or 30" (would run at: 1:30, 2:00, 2:30, 3:00, etc)
这意味着“在每小时的分钟为 0 或 30 时运行”(将在:1:30、2:00、2:30、3:00 等运行)
it's another way to accomplish the same results as example #2
这是实现与示例 #2 相同结果的另一种方法
example #4
示例#4
19 * * * * your_command
19 * * * * your_command
this means "run when the minute of each hour is 19" (would run at: 1:19, 2:19, 3:19, etc)
这意味着“在每小时的分钟为 19 时运行”(将在:1:19、2:19、3:19 等运行)
example #5
示例#5
*/19 * * * * your_command
*/19 * * * * your_command
this means "run when the minute of each hour is evenly divisible by 19" (would run at: 1:19, 1:38, 1:57, 2:19, 2:38, 2:57 etc)
这意味着“当每小时的分钟被 19 整除时运行”(将在:1:19、1:38、1:57、2:19、2:38、2:57 等运行)
note: several refinements have been made to this post by various users including the author
注意:包括作者在内的各种用户对这篇文章进行了一些改进
回答by Mohsen Abasi
You can use both of ',' ORdivide '/' symbols.
But, '/' is better.
Suppose the case of 'every 5 minutes'. If you use ',', you have to write the cron job as following:
您可以同时使用 ' ,'或除以 ' /' 符号。
但是,' /' 更好。
假设“每 5 分钟”的情况。如果使用 ' ,',则必须按如下方式编写 cron 作业:
0,5,10,15,20,25,30,35,.... * * * * your_command
It means run your_command in every hour in all of defined minutes: 0,5,10,...
However, if you use '/', you can write the following simple and short job:
这意味着在所有定义的分钟内每小时运行 your_command: 0,5,10,...
但是,如果使用“/”,则可以编写以下简单而简短的作业:
*/5 * * * * your_command
It means run your_command in the minutes that are dividable by 5 or in the simpler words, '0,5,10,...'
So, dividable symbol '/' is the best choice always;
这意味着在可被 5 整除的分钟内运行 your_command 或更简单的词“0,5,10,...”,
因此,可整除符号“/”始终是最佳选择;