[ale] cron entry that runs the 2nd saturday of every month

David Tomaschik david at systemoverlord.com
Sat Aug 27 17:01:53 EDT 2011


On 08/27/2011 04:26 PM, The Don Lachlan wrote:
> On Fri, Aug 26, 2011 at 02:25:40PM -0400, Geoffrey Myers wrote:
>> Is it possible?
> 0 0 8-14 * 6  /usr/bin/foo
>
> That says, "Run foo on days of the month between 8th and 14th (inclusive)
> that are Saturdays."
>
> There will be only one Saturday every month in that window and it will
> always be the second one of the month.
>
> I think others in the thread explained this but didn't give specific syntax
> and so others continued on script folly.
>
> -L

Unfortunately, that would actually cause the command to be run on the
8th through the 14th, and on all Saturdays. Per crontab(5):

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 (i.e.,
aren't *), the command will be run when either field matches the cur‐
rent 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. One can, however, achieve
the desired result by adding a test to the command (see the last exam‐
ple in EXAMPLE CRON FILE below).

As a pointer for everyone: most modern versions of cron support 3 letter
codes for month & day of week. Particularly for day of week, make use of
this -- in some parts of the world, the week starts on different days.
Three letter codes (Mon, Tue, etc.) are unambiguous without reading the
man page.

-- 
David Tomaschik, RHCE, LPIC-1
System Administrator/Open Source Advocate
OpenPGP: 0x5DEA789B
http://systemoverlord.com
david at systemoverlord.com



More information about the Ale mailing list