Set a Cron Every Certain Hours Between Certain Hours

Set a Cron Every Certain Hours Between Certain Hours

How can I set a cron to run every 2 hours between 8 am and 5 pm for example? Is this possible?

2

2 Answers

Actually, Alex's (former) solution will run every minute, every 2 hours between 8 am and 3pm.  The right solution is:

0 8-17/2 * * * /path/command

Or even:

0 8,10,12,14,16 * * * /path/command

Which of course looks less nice, but still does what requested...

2
0 8-17/2 * * * your_command.sh

Your Answer

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

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.