# Is it possible to get a cron job to run between certain hours only?

I'm editing a crontab for a job that I want to run every minute but only between the hours of 10pm and 2am. Outside this time I'd like it to run every 10 minutes, I'm not sure if this is possible though.

Any help appreciated, thanks.

-
figured this out: */1 22-2 * * * and */10 2-22 * * * –  Darryl Jul 15 '10 at 11:58

It would probably be best to have it a 2 separate jobs, one for each hourly group

* 22-23,0-2 * * * command
*/10 2-22 * * * command

-

It's easiest to do in two lines.

* 22-23,0-2 * * * command
*/10 2-22 * * * command


This might be specific syntax for vixie cron, though. Check man 5 crontab

-

Yes, that is possible. Taken from crontab(5):

Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an hours'' entry specifies execution at hours 8, 9, 10 and 11.

Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: 1,2,5,9'', 0-4,8-12''.

(Assuming Vixie Cron)

-