Crontab每15分钟跑一次,凌晨3点除外?

时间:2022-05-02 02:29:43

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点跑步,但我不想让另一个在同一时间跑步……

3 个解决方案

#1


88  

With one cron line, no. With three, yes:

只有一条线,不行。有三个,是的:

# 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

#2


6  

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:

cron行:

*/15 * * * * ~/path/to/file

Hope anyone uses my solution too.

希望大家也能使用我的解决方案。

#3


0  

 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

#1


88  

With one cron line, no. With three, yes:

只有一条线,不行。有三个,是的:

# 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

#2


6  

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:

cron行:

*/15 * * * * ~/path/to/file

Hope anyone uses my solution too.

希望大家也能使用我的解决方案。

#3


0  

 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