Operating System - HP-UX
1834448 Members
2186 Online
110067 Solutions
New Discussion

Interpretation of cron - easy points

 
SOLVED
Go to solution
OFC_EDM
Respected Contributor

Interpretation of cron - easy points

Here's my interpretation of some cron settings:

0 3 28 10 5
Run at 3 AM every Friday or 28th day of October.

0 3 25 10 2
Run at 3 AM every Tuesday or 25th day of October.

00 03 08 11 2
Run at 3 AM every Tuesday or 8th day of November.

Am I correct?
The Devil is in the detail.
13 REPLIES 13
Patrick Wallek
Honored Contributor

Re: Interpretation of cron - easy points

No, you aren't correct.

0 3 28 10 5
Will run your command on Oct. 28 AND every Friday.

0 3 25 10 2
will run your command on Oct. 25 AND every Tuesday.

00 03 08 11 2
Will run your command on Nov. 8 AND every Tuesday.

The values are cumulative. Have a look at 'man crontab' for more information.
A. Clay Stephenson
Acclaimed Contributor

Re: Interpretation of cron - easy points

Yes, in this context the monthdays and the weekdays logical OR rather than logical AND.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Interpretation of cron - easy points

I suppose one should be careful here not to confuse English "or" with Logical "OR". In any event, if either condition is satisfied (e.g. Oct. 28th OR Friday) the command will run. The common mistake is to assume that both conditions must be satisfied (Logical AND) when only one condition (Logical OR) must be satisfied.
If it ain't broke, I can fix that.
Patrick Wallek
Honored Contributor

Re: Interpretation of cron - easy points

Kevin,

Sorry I slightly misread your interpretations the first time around. Yes you are correct. I somehow originally saw it without the 'or' separating your week days and dates.

OFC_EDM
Respected Contributor

Re: Interpretation of cron - easy points

I've confused myself..


Let's take:

0 3 25 10 2
Run at 3 AM every Tuesday or 25th day of October.

In my wording above some people think it includes Tuesdays outside of October as well. Which is not what I meant.

So that begs the question...will it run on Tuesdays in months other than October?
The Devil is in the detail.
Patrick Wallek
Honored Contributor

Re: Interpretation of cron - easy points

A crontab with '0 3 25 10 2':

will run on Oct. 25 AND EVERY TUESDAY.

Basically if the day is Tuesday, the job runs. OR if the date is Oct. 25, the job runs.

It doesn't matter if the Tuesday is in Oct., Nov., Dec., or whatever. It'll run every Tuesday.
Jeff_Traigle
Honored Contributor
Solution

Re: Interpretation of cron - easy points

On that one...

Only on the Tuesdays in October or on the 25th of October

The others would similarly be restricted by the month of the year configuration.
--
Jeff Traigle
OFC_EDM
Respected Contributor

Re: Interpretation of cron - easy points

Interesting. But at least you're all thinking what I'm thinking and I've passed the sanity check.

However I have the jobs setup with those cron settings but they fail to run on the weekday specified (Tuesday or Friday).

Any suggestions on where to start troubleshooting this?
The Devil is in the detail.
A. Clay Stephenson
Acclaimed Contributor

Re: Interpretation of cron - easy points

Rather than adding to the confusion by listing a crontab specification, why don't you state in English when you want this job to be run and then let someone suggest the crontab entry(s) to accomplish this.
If it ain't broke, I can fix that.
OFC_EDM
Respected Contributor

Re: Interpretation of cron - easy points

I'm listing the crontab entry because I'm trouble shooting an existing crontab entry for a user who's not available today.

And I wanted to reverse engineer the problem because that usually generates more accurate answers.

But I am in the process of getting a description from the user of when they want the jobs run. Will post when available.

Thanks
The Devil is in the detail.
OFC_EDM
Respected Contributor

Re: Interpretation of cron - easy points

Looks like the user just wanted to run a job on a specific date.

So I told them to take out the "day of week".

Example

00 03 08 11 *
To run the job ONLY on November 8th.

When she used
00 03 08 11 2
It would run everyt Tuesday as well which is not what she wanted.

That works right?
The Devil is in the detail.
A. Clay Stephenson
Acclaimed Contributor

Re: Interpretation of cron - easy points

Yes, that is a correct approach; however, you should note that cron is intended to execute repetitive tasks. If the intent is to run this task each year then cron is appropriate but if the intent is to run this just one time then "at" is the better choice.
If it ain't broke, I can fix that.
OFC_EDM
Respected Contributor

Re: Interpretation of cron - easy points

Easy points I said in the subject.
Sorry it took 2 years to assign them !!

Cheers
The Devil is in the detail.