Crontab run every 15 minutes except at 3AM?

后端 未结 3 373
小鲜肉
小鲜肉 2020-12-05 05:59

Is it possible to have a cronjob run every 15 minutes (over every hour etc..) except for at 3AM?

I have another special cronjob I want to run at 3AM, but I don\'t wa

相关标签:
3条回答
  • 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
    
    0 讨论(0)
  • 2020-12-05 06:45
     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
    
    0 讨论(0)
  • 2020-12-05 06:47

    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.

    0 讨论(0)
提交回复
热议问题