Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to specify a job that runs every 5 minutes between some start time and some end time on business days in a crontab?

Update I think it's relevant that my start and end times are not at round hours. So, specifying 9-5 in the hour column isn't enough. I want 9:30-17:30.

share|improve this question
up vote 17 down vote accepted

You'll have to do it piecewise:

30-59/5 9 * * *
*/5 10-16 * * *
0-30/5 17 * * *
share|improve this answer

If Ignacio Vazquez-Abrams's answer doesn't really work for you, for example because the script needs a large number of parameters or the invocation criteria are non-trivial (or not time-bound), then an alternative approach is to make a simple wrapper script, call the wrapper script at regular intervals, and have the wrapper script check the current time and invoke the main script.

For example:


# Check to see if we should run the script now.
HOUR=$(date +%H)
MINUTE=$(date +%M)
if test $HOUR -lt 9; then exit 0; fi
if test $HOUR -eq 9 -a $MINUTE -lt 30; then exit 0; fi
if test $HOUR -eq 17 -a $MINUTE -gt 30; then exit 0; fi
if test $HOUR -gt 17; then exit 0; fi

# All checks passed; we should run the script now.
exec ... long list of parameters ...

This allows for encoding execution criteria more complex than cron's syntax readily allows for, at the relatively small expense of invoking a shell and a separate script regularly.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .