Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab running when not expected!

Status
Not open for further replies.

tarn

Technical User
Aug 19, 2001
534
GB
Hi all,
Well it Sunday and I've just missed the first half of the Spanish MotoGP due to a strange behavior of crontab.

Last week I set the servers to do an auto shutdown for some power work to begin in the early hours of Saturday, this is the crontab:

# Set to down the servers on Saturday for power work
57 04 8 6 6 /sbin/init 0

So I would expect that at 4:57 Saturday the 8th June, that the servers would go down into the ok prompt and could be powered off safely ..... And they did.

In an attempt to keep the history, I decided not to remove the job from cron as the cron had been told that if Saturday was the 8th and the month was June and the time was 04:57 then and ONLY then do the shutdown !!! But guess what it done ?

Yup! it saw that yesterday was a Saturday and ignored that it was NOT the 8th and went ahead and done the shutdown.

Now that's what I call mean, is this usual, can I not trust crontab to do what it's told, I can see no reference in the Man pages that says adding the day will override the date!

Is this a bug or am I being stupid?

Systems = Red Hat Linux 7.2

(I need to report to managment Tomorrow so I would like some of you peoples' thoughts, If its just me being stupid then I'll put my hands up and say so)

Cheers
Tarn
 
I don't think you did anything stupid. I looks to me that after running that one time, it will not run again until the next June 8th falls on a Saturday. Next year, June 8th falls on a Sunday so it will be a long time before it should run again. Unless you have something scheduled that tells cron to run ALL jobs on ANY Saturday, I don't know what could have happened.
 
Thanks RhythmAce, that makes me feel better at least, I'm not sure that it will cut any mustard with "Managment" though!

I'm going to run some tests over the next few weeks on the test environment and see if I can replicate it.

I bet it's a bug in crond, I couldn't have been a typo as I had 9 servers that all done the same and I hand typed "all" the crontabs at all 9 consoles.

Strange ?

Thanks again for your comment ... Enjoy the rest of your Sunday

:¬)
 
Perhaps I am interpretating this wrong, but this is a case of an "OR" function instead of an "AND" function.

If so, then your entry will run the command at 04:57 on the 8th June OR whenever the day is Saturday.

This seems to be a "catch" in crontab settings, read cron's man page carefully. See below, the key lies in the "at least one of the two" bit:

Commands are executed by cron(8) when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
Just as I thought, pulled this off a web site:

Note: The day of a command's execution can be specified by two fields -- day of month, and day of week. If both fields are restricted (ie, aren't *), 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.

IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
Yeah, Thanks everyone I've just tracked down the same information both on Linux and Solaris man pages.

I guess the moral of this thread is read the man pages carefully and do not take things at face value.


Thanks everyone for the support, and I hope that this will go a little way to preventing someone else making the same mistake.

Cheers
Tarn (L.)
"So I guess iy's just a case of putting my hands up"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top