Linux Crontab 每 15 分钟运行一次,凌晨 3 点除外?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8764150/
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
Crontab run every 15 minutes except at 3AM?
提问by Eric Seifert
Is it possible to have a cronjob run every 15 minutes (over every hour etc..) except for at 3AM?
除了凌晨 3 点之外,是否可以每 15 分钟(每小时等)运行一次 cronjob?
I have another special cronjob I want to run at 3AM, but I don't want the other one to run at the same time...
我有另一个特殊的 cronjob 我想在凌晨 3 点运行,但我不希望另一个同时运行...
采纳答案by fge
With one cron line, no. With three, yes:
有一个 cron 行,没有。三个,是的:
# Every 15 minutes except for 3:00-3:59
*/15 0-2,4-23 * * * thejob
# 3:15, 3:30, 3:45
15-45/15 3 * * * thejob
# 3:00 dead
0 3 * * * otherjob
回答by richrosa
0,15,30,45 0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * * your cron job
回答by Eric
I made my own solution, but I wanted to see what other people thought of!
我做了自己的解决方案,但我想看看其他人的想法!
I put this on the top of my desired script. I wanted it to not run at the half hour either so it doesn't do it on both.
我把它放在我想要的脚本的顶部。我希望它也不要在半小时内运行,所以它不会同时运行。
On top of the script:
在脚本之上:
if [ $(date +%M) = 00 ] || [ $(date +%M) = 30 ]
then
exit
fi
The cron line:
克隆线:
*/15 * * * * ~/path/to/file
Hope anyone uses my solution too.
希望有人也使用我的解决方案。