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

Re: [OT] Cron and day of the week



On Wed, Mar 25, 2009 at 04:25:45PM +0000, T o n g (mlist4suntong@yahoo.com) wrote:

> I know we can put day of the week info as cron schedules, but how can I 
> define:

Cron syntax can't handle these, but with an extra test in crontab they
can be done. Assuming you want to run "myprog" at noon:

> - first Monday of the month

0 12 * * 1 [ `date +%d` -le 7 ] && myprog

or

0 12 1-7 * * [ `date +%w` = 1 ] && myprog

> - second Monday of the month

0 12 8-14 * * [ `date +%w` = 1 ] && myprog

> - last Monday of the month

0 12 * * * 1 [ "`date +%m`" != "`date --date week +%m`" ] && myprog

The last depends on Gnu date (but that's what Debian uses,
so it's appropriate here): "date --date week" gives the date
one week from now, and if the month is different, today
is the last Monday.

-- 
Tapani Tarvainen


Reply to: