Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am getting Bad Hour error for below peice of code in crontab

*/05 17-05 * * * wget -q -O /dev/null "http://abcd/cron/abcd"

Is there any issue with this. I want the cron to run from evening 5 PM to morning 5 AM

share|improve this question

1 Answer 1

up vote 3 down vote accepted

As you are not specifying which system you are using, I am hoping your system use a "Vixie" or "Vixie"-related crontab utility.

Still:

  • 17-05: is not considered a proper range (the lower limit being greater than the higher limit of the range).

You could instead write: "17-23,00-05"

From man 5 crontab:

 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.

So, sure nothing really forbiding you to write an interval the way you did.

The Extensions part of man 5 crontab is also interesting regarding how other crontab utilities would allow you specify more than a simple range (your system might be one of these):

 Lists and ranges are allowed to co-exist in the same field.
 "1-3,7-9" would be rejected by ATT or BSD cron -- they want to
see "1-3" or "7,8,9" ONLY.

So, as you can see, it really depends on your system crontab ability to understand what you mean by "17-05".

For more information:

share|improve this answer
    
but cron wont work for 1 hour between 11PM and 12AM right? –  Hacker Apr 7 at 7:32
    
@Hacker it will work for those times as expected. –  cpugeniusmv Apr 7 at 10:48
    
@Hacker: 11PM=23 and 12AM=0 ... so it will go up to 11:55PM and then go for 0:00, that is no stop –  Ouki Apr 7 at 12:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.