热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

我怎么才能每30分钟得到一个cron?-HowwouldIgetacronjobtorunevery30minutes?

Imlookingtoaddacrontabentrytoexecuteascriptevery30minutes,onthehourand30minutes

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分,时间是小时30分。我有以下内容,但它似乎不在0上运行。

*/30 * * * *

What string do I need to use?

我需要使用什么字符串?

The cron is running on OSX.

cron在OSX上运行。

6 个解决方案

#1


434  

Do:

做的事:

0,30 * * * * your_command

#2


70  

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 should find a clear failure message.

根据官方的Mac OS X crontab(5)手册,支持/语法。因此,要找出它为什么不适合您,您需要查看cron的日志。在这些日志中,您应该找到一个明确的失败消息。

Note: Mac OS X appears to use Vixie Cron, the same as Linux and the BSDs.

注意:Mac OS X似乎使用了Vixie Cron,与Linux和BSDs相同。

#3


59  

crontab does not understand "intervals", it only understands "schedule"

crontab不理解“间隔”,它只理解“schedule”

valid hours: 0-23 -- valid minutes: 0-59

有效时间:0-23——有效时间:0-59

example #1

示例# 1

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

* * * * *你的命令

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

你的命令

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

你的命令

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

注意:包括作者在内的不同用户对这篇文章做了一些改进

#4


9  

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.

您可以通过简单的web搜索找到其他信息(例如启动Wikipedia页面)。

#5


5  

You mention you are using OS X- I have used cronnix in the past. It's not as geeky as editing it yourself, but it helped me learn what the columns are in a jiffy. Just a thought.

你说你在用OS X-我以前用过cronnix。它并不像你自己编辑它那样令人讨厌,但它帮助我迅速了解了专栏是什么。只是一个想法。

#6


1  

You can use both of ',' OR divide '/' 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 job如下:

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或更简单的单词,'0,5,10,…所以,可除符号/'是最好的选择;


推荐阅读
author-avatar
个信2502857367
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有