Crontab Formatting - every 15 minutes

女生的网名这么多〃 提交于 2019-12-17 10:58:19

问题


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 * * * * ------------------------

I'm pretty sure this just runs the first 15 minutes of every hour.

I think that crontab allows users to specify exact times to run, namely:

0, 15,30,45 * * * * -------------------------

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?


回答1:


Crontab doesn't remember what time you "started" (presumably the time you executed the crontab -e or crontab filename command).

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

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

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.




回答2:


You would format the crontab like this to get it to run every 15 minutes.

*/15 * * * * [path/to/script]



来源:https://stackoverflow.com/questions/15033542/crontab-formatting-every-15-minutes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!