cron 工具 每分钟_如何设置cron每40分钟/ 25分钟运行我的脚本?

I want a script to run every 40mins beginning on the 40th minute.

so that means:

00:40, 01:20, 02:00, 02:40, 03:20...

So I made this entry to cron:

*/40 * * * * /path/to/script/foo.sh

Unfortunately this runs the script every 40th minute of the hour:

00:40, 01:40, 02:40...

The same goes with the script that I meant to run every 25mins.

Am I missing something here?

ANSWERS

Alright, in case you happen to drop by here having the same problem

here's how I solved it:

# 40mins-interval

40 0 * * * /path/foo.sh (0)

0,40 2-22/2 * * * /path/foo.sh (2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22)

20 1-23/2 * * * /path/foo.sh (1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23)

# 25mins-interval

25,50 0 * * * /path/foo.sh (0)

0,25,50 5-20/5 * * * /path/foo.sh (5, 10, 15, 20)

15,40 1-21/5 * * * /path/foo.sh (1, 6, 11, 16, 21)

5,30,55 2-22/5 * * * /path/foo.sh (2, 7, 12, 17, 22)

20,45 3-23/5 * * * /path/foo.sh (3, 8, 13, 18, 23)

10,35 4-19/5 * * * /path/foo.sh (4, 9, 14, 19)

Notes:

1. There will still be collisions in this schedule (i.e: see schedules that run on the 0th and 10th minutes on both intervals).

2. The script won't run at an exact interval from its last run today going on the next day (i.e: 25min interval ends @23:45 today, begins @00:25 next day).

解决方案

It always splits the current hour only.

40/40 = 1 so it runs every 40th minute of an hour.

*/5 would do 5, 10, 15, 20, ...

You should go for larger intervals.

Do */30 for your 25 minute interval and every 60 minutes for your 40 minutes interval.

Otherwise set up two crontabs for your script:

0,40 */2 * * * /path/to/script/foo.sh

20 1,3,5,7,11,13,15,17,19,21,23 * * * /path/to/script/foo.sh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值