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

RE: cron: nth <weekday> of month?




> -----Original Message-----
> From: Karsten M. Self [mailto:kmself@ix.netcom.com]
> Sent: Wednesday, April 25, 2001 6:58 AM
> To: debian-user
> Subject: 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?
> 
It is messy, isn't it.  What I did was to put the day of the week in the
cron file and then tested (using date) in the script to see if it is
the right one.  Unfortunately, this splits the logic of when the thing
runs into two places.  I thought using the day of the week in cron made
it a little clearer as to what was going on.  I have a dislike for at
since it is a little harder to get to if you want to cancel it.  I don't
think there is a clean way to do this.  I hate having the logic split
like that but life goes on anyway.  It works and there are other battles...

jim
> -- 
> 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



Reply to: