Run script every 4 minutes but don't run from 3:00 to 3:40
Sebastian Wright
Issue. In cron, what is the best and simplest way to configure run example.sh every 4 minutes in hour, but from 3:00 to 3:40 don't?
I tried this.
*/4 0-3 * * * example.sh
*/4 4-0 * * * example.sh
40,44,48,52,56 4 * * * example.shI believe there is a simpler way.
31 Answer
Stack Overflow has a good answer similar to your problem:
In this answer a job runs every 15 minutes except blackout period from 3am to 4am at which time another job is run:
# 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
If you don't have another job to run during the blackout period remove the last two lines.
You can combine your two lines of:
*/4 0-3 * * * example.sh
*/4 4-0 * * * example.shWith one line of:
*/4 0-2,4-23 * * * example.shThen for your last complicated line:
40,44,48,52,56 4 * * * example.shReplace it with:
40-59/4 3 * * * example.sh