Crontab 格式化 - 每 15 分钟一次 [英] Crontab Formatting - every 15 minutes
问题描述
我试图让一个简单的 crontab 作业每 15 分钟运行一次,但在决定如何格式化时间时遇到了麻烦.
I'm trying to get a simple crontab job to run every 15 minutes and am having trouble deciding how to format the timing.
我一直在放下的是以下内容:
What I've been putting down is the following:
15 * * * * ------------------------
我很确定这只是每小时的前 15 分钟.
I'm pretty sure this just runs the first 15 minutes of every hour.
我认为 crontab 允许用户指定确切的运行时间,即:
I think that crontab allows users to specify exact times to run, namely:
0, 15,30,45 * * * * -------------------------
但是如果我想从我启动它的那一刻起每 15 分钟运行一次 crontab(它可能不一定是一个可被 15 整除的值),我将如何进行格式化/这可能吗?
But if I wanted to run the crontab every 15 minutes from the moment I start it, (which may not necessarily be on a value divisible by 15), how would I go about formatting that/is that possible?
推荐答案
Crontab 不记得您开始"的时间(大概是您执行 crontab -e
或 crontab 的时间文件名
命令).
Crontab doesn't remember what time you "started" (presumably the time you executed the crontab -e
or crontab filename
command).
如果您想从任意时间开始每 15 分钟运行一次作业,则必须指定该时间.这:
If you want to run the job every 15 minutes starting from an arbitrary time, you'll have to specify that time. This:
7-59/15 * * * * command
将在每小时 7、22、37 和 52 分钟后运行.假设您正在运行 Vixie cron,这是最常见的实现.为了更好的便携性,您可以使用:
will run at 7, 22, 37, and 52 minutes after each hour. That's assuming you're running Vixie cron, which is the most common implementation. For better portability, you can use:
7,22,37,52 * * * * command
请记住,前 5 个字段中的任何一个都不能有空格;0, 15,30,45
,正如您在问题中所说,无效.
And remember that you can't have spaces within any of the first 5 fields; 0, 15,30,45
, as you had in your question, is invalid.
这篇关于Crontab 格式化 - 每 15 分钟一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!