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 scheduled a job like this:

*   *    6-8  *  1-5  echo "test" >>/tmp/test.log 2>&1

I expect this job to run only on 6th,7th,8th, these 3 days. but today is 18th, it still runs. What is wrong with this job? What shall I do if I want it to run a some specific days?

share|improve this question
    
Not sure about this, but from what you posted, the spaces/tabs between the columns are not all the same. –  MaxMackie Feb 18 '13 at 1:41
    
I tried reformatting my crontab so that every 2 fields are separated by 1 space. it doesn't work either. –  David Dai Feb 18 '13 at 1:44
add comment

2 Answers 2

up vote 4 down vote accepted

The day-of-month and day-of-week positions are OR'd, so in your example, the cron will run on the 6th, 7th, or 8th or Monday through Friday. Since the 18th is a Monday, it runs. It's not exactly intuitive.

To get the behavior I think you desire (run on the 6th, 7th, and 8th if they are a weekday), then you can do something like this:

* * * * 1-5 date '+%d' | grep '[678]' && echo "test" >>/tmp/test.log 2>&1
share|improve this answer
    
day-of-month and day-of-week are not exactly OR'd, right? if I use * * 6-8 * *, the day-of-week field matches every day, but it runs only on 6-8. –  David Dai Feb 18 '13 at 2:04
1  
ahh. I just found this in man 5 crontab. Note: The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the current time. For example, "30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday. –  David Dai Feb 18 '13 at 2:05
add comment

The day-of-the-month specification (field-3; one-relative) and the day-of-the-month field (5) are both specified. In this case, a match for either means that your crontab runs.

share|improve this answer
add comment

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.