1845937 Members
5585 Online
110250 Solutions
New Discussion

cron foo

 
SOLVED
Go to solution
jerry1
Super Advisor

cron foo

I must not be awake yet. I had a cron set
to run on Aug. 26 at 8:00am on the 2nd day
of the week, only. But it ran on Aug. 19 at
8:00am on the second day of the week. Does
anyone see what is wrong with this cron
entry or know of such a thing happening??

0 8 26 8 2

cron log entry on the run:
> root 25836 c Tue Aug 19 08:00:00 CDT 2008
9 REPLIES 9
Pete Randall
Outstanding Contributor
Solution

Re: cron foo

From the man page:

"Note that the specification of days can be made in two fields: monthday and weekday. If both are specified in an entry, they are cumulative. For example,

0 0 1,15 * 1 command

runs command at midnight on the first and fifteenth of each month, as well as every Monday."


Pete

Pete
SKR_1
Trusted Contributor

Re: cron foo

0 8 26 * * < command >

Thanks

SKR
jerry1
Super Advisor

Re: cron foo

All fine. But it does not explain why
this ran on Aug 19 at 8am on the 2nd day
of the week when it was setup to run
Aug 26 at 8am on the 2nd day of the week:

Minute Hour Dayofmonth Monthofyear Dayofweek
0 8 26 8 2
SKR_1
Trusted Contributor

Re: cron foo

It was tuesday on 19 and you had specified 2 in crontab entry, that's why it ran on 19.
It will also run on 26 and on every second day of the week.


Thanks

SKR
Pete Randall
Outstanding Contributor

Re: cron foo

OK, I'll translate for you:

"Note that the specification of days can be made in two fields: monthday and weekday. If both are specified in an entry, they are CUMULATIVE. For example,

0 8 26 8 2

runs command at 8:00AM on the twentysixth of each month, as well as EVERY Tuesday."


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: cron foo

Hi Jerry:

The Forum is a funny place. Similar questions are asked within days of one another.

Examine this post's crontab command and my comment of how it is interpreted:

http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1260835

Pete has pointed you to the manpages. They don't lie [at least in this case] :-}

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: cron foo

To put it a different way:

You are trying to be redundant, by telling cron to run the job on Tuesday Aug. 26. In this case it backfired on you though because cron does NOT do an 'AND' with the day and date fields. You expected it do something like, IF time = 8:00 AM AND today is TUESDAY AND the date is Aug. 26 THEN run your command.

However what cron does:

If time = 8:00 AM AND (today is TUESDAY ***OR*** the date is Aug. 26) THEN run your command.

Hopefully it is clear now?
jerry1
Super Advisor

Re: cron foo

Okay, I'm awake now.

Better.

0 8 26 8 *
Dennis Handly
Acclaimed Contributor

Re: cron foo

It is tztab(4) that uses AND of the day of week and the day of month.