Cron running at wrong time

I am trying to schedule a script to run once a month in cron on a Saturday only.

In my cron I have the following:

Code:
00 3 25-31 * 6 root /support/zfsscrub.sh | mail -s "ZFS scrub of all pools" root@domain.com

But for some reason I received an email this morning to say that it had been run which I thought odd. Today is Saturday so that parts correct but the day is wrong. I specified that the script run only on days 25-31 of the month but it ran today which is the 15.

What is wrong with this cron entry?

I did look at using @monthly in cron but then it runs at midnight.
 
That's the way cron works, see crontab(5)

The command will run whenever day-of-week or day-of-month matches, that is every saturday + daily between 25-31.
 
You got bit by the special "month of the day, day of the week" crontab rule, which states that if you specify both, the conditions are treated as a "or", not a "and" (is it day 25-31 of the month? Ok, run. Or is it Saturday, Ok, run). Your "last Saturday of the month" rule is not a regular interval that you can specify in a crontab; note that it would have not run this month of Feb 2014 since the last Saturday falls outside the day range you were trying.

My suggestion: set up the crontab entry to run every Saturday, and then either add to the top of the script you're running or as a wrapper around what you want to run:
Code:
[ `date +%m` = `date -v +1w +%m` ] && exit
<your actual script or a call to what you want to run here>
 
In the end I just went with the following:

Code:
00 3 28 * * root /support/zfsscrub.sh

I don't mind that it runs on the 28th of every month but originally I just thought it would be nice to have it run on the last Saturday of every month.

Thanks for the tips!
 
Back
Top