46

I need a cron statement to run for few hours eg 1-8 then 10-15. In this case will the following statement work,

0 1-8,10-15 * * * 

If not can anyone help me?

Thanks in advance, Gnik

Ardee Aram
  • 4,740
  • 8
  • 36
  • 37
Gnik
  • 7,120
  • 20
  • 79
  • 129

2 Answers2

64

You cannot, you can use either multiple values OR a range

0 1,2,3,4,5,6,7,8,10,11,12,13,14,15 * * *

Source:

Time tags are separated by spaces. Do not use spaces within a tag, this will confuse cron. All five tags must be present. They are a logical AND of each other. There is another space between the last time tag and the first command.

A time tag can be a wildcard "*", which means "all". It can be one value, several values, a range, or a fractional range.

OmnipotentEntity
  • 16,531
  • 6
  • 62
  • 96
28

I find it more readable to have two crontab entries:

0 1-8 * * * ...
0 10-15 * * * ...
FuePi
  • 1,958
  • 22
  • 18
  • 7
    +1. much cleaner/concise. downside is that if something in the command changes, you now have multiple places to edit it – K Raphael Dec 14 '15 at 15:52
  • 4
    you could use a bash script to encapsulate the parameters, Then, on crontab just call a single bash script for both entries. – eddy85br May 24 '17 at 18:35