[Techtalk] Age-old cron problem

Conor Daly c.daly at met.ie
Mon Dec 10 10:09:43 UTC 2007


On Sun, Dec 09, 2007 at 06:40:21PM -0700 or thereabouts, Nicoya Helm wrote:
> 
>    I've encountered this problem before, but didn't really need to solve
>    it, so didn't.  This time, I do.
>    It is the age-old cron dilemma of scheduling things to repeat in ways
>    like "every n-day day of the nth week of the month" or "every other
>    n-day of the week".  For example, the 3rd Friday of every month.  Or,

I don't think cron can do this one.  From 'man 5 crontab':

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

My initial thought of:

	30 4 15-21 * 5

to run on a friday between the 15th and 21st of the month (the third friday
should always have those dates) won't work because it will run every friday
and every 15th to 21st.  In this case, you probably need suitable logic
within the program to decide if it's the third friday.  Checking that the
day of the month is in the range 15 to 21 and running every friday should do
that.


>    my specific goal, every other Sunday.

Every second Sunday, OTOH, looks possible.

       23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
       5 4 * * sun     echo "run at 5 after 4 every sunday"

So, by inference, 

       5 4 * * sun/2     echo "run at 5 after 4 every second sunday"

should work?

Conor
-- 
Conor Daly,                   
Met Eireann, Glasnevin Hill,  
Dublin 9, Ireland             
Ph +3531 8064276 Fax +3531 8064247

*********************************************************************************
This e-mail and any files transmitted with it are confidential and intended solely for the addressee. If you have received this email in error please notify the sender.
This e-mail message has also been scanned for the presence of computer viruses.

Ta an riomhphost seo, agus aon chomhad ata nasctha leis, faoi run agus is don te a seoladh chuige amhain e. Ma tharla go bhfuair tu an riomhphost seo tri dhearmad cuir in iul don te a sheol e led' thoil.

Ta an teachtaireacht riomhphoist seo scuabtha le bogearrai frithvireas.
********************************************************************************
NorthBridge Mail Server id e9yrhg43fncvj3974vjenw



More information about the Techtalk mailing list