[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

cron: nth <weekday> of month?



I've got a job I'd like to run once a month, on a set day of the week,
say, the first Sunday of the month.  Suggestions as to how to do this
with cron?

My understanding is that I can specify day of month, or weekday, but if
both are specified the condition is treated as an OR (if first week of
month OR Sunday, then do...).  

E.g.:  

    48 2 1 * 7 do-stuff

...would run on the first of the month, and each Sunday.

I could set a job to run either each Sunday, or each of the first seven
days of the month, and test the appropriate other condition.  Or
schedule an 'at' job for the first coming Sunday (at a later time than
the cron job runs).  Actually, this last is probably the cleanest
solution:

    1 0 1 * * echo "command -args" | at 1:07 sunday

...should do the trick.

You're scheduling a command to schedule a command.

For the 2nd, 3rd, and 4th weeks of the month, change the day to the 8th,
15th, or 22nd, respectively.

Thoughts, anyone?

-- 
Karsten M. Self <kmself@ix.netcom.com>    http://kmself.home.netcom.com/
 What part of "Gestalt" don't you understand?       There is no K5 cabal
  http://gestalt-system.sourceforge.net/         http://www.kuro5hin.org

Attachment: pgpJyvbd69Fgy.pgp
Description: PGP signature


Reply to: