Run a cron job every 5 minutes between two times
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5
--
Chapters
00:00 Run A Cron Job Every 5 Minutes Between Two Times
00:22 Accepted Answer Score 26
00:32 Answer 2 Score 1
01:17 Thank you
--
Full question
https://superuser.com/questions/133456/r...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#cron #crontab
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5
--
Chapters
00:00 Run A Cron Job Every 5 Minutes Between Two Times
00:22 Accepted Answer Score 26
00:32 Answer 2 Score 1
01:17 Thank you
--
Full question
https://superuser.com/questions/133456/r...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#cron #crontab
#avk47
ACCEPTED ANSWER
Score 26
You'll have to do it piecewise:
30-59/5 9 * * * script.sh
*/5 10-16 * * * script.sh
0-30/5 17 * * * script.sh
ANSWER 2
Score 1
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:
#/bin/bash
# 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 script.sh ... 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.