Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Run script every 4 minutes but don't run from 3:00 to 3:40

Writer 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.sh

I believe there is a simpler way.

3

1 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.sh

With one line of:

*/4 0-2,4-23 * * * example.sh

Then for your last complicated line:

40,44,48,52,56 4 * * * example.sh

Replace it with:

40-59/4 3 * * * example.sh

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy