Newsgroups: comp.unix.wizards
Path: utzoo!utgpu!watserv1!dmcanzi
From: dmcanzi@watserv1.waterloo.edu (David Canzi)
Subject: Re: Cron - First Saturday of the month
Message-ID: <1990Aug8.214539.1264@watserv1.waterloo.edu>
Organization: People's Democratic Republic of Uniwat
References: <19744@orstcs.CS.ORST.EDU> <1990Aug8.185745.16606@iwarp.intel.com>
Date: Wed, 8 Aug 90 21:45:39 GMT
Lines: 52

In article <1990Aug8.185745.16606@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes:
>In article <19744@orstcs.CS.ORST.EDU>, curt@oce (Curt Vandetta) writes:
>|   I'm wondering if anyone has a way of making cron run a job on the
>|   first Saturday of every month?  
>
>3 4 1-7 * 6 command
>
>to make 'command' run at 4:03am... adjust the first two fields as
>necessary.  Remember, the parameters are "and"-ed together.
>
>#ifdef FLAME_ABOUT_INAPPROPRIATE_GROUP
>
>This is not a wizard question.  Wizards generally know cron things,
>especially things that can be found with "man 5 crontab".  Do not post
>to wizards unless you *are* a wizard, and if you have any doubt about
>whether you are a wizard or not, you're not!
>
>Now, if you had asked which versions of cron did *not* provide /etc in
>the PATH... that'd be a wizard question. :-)

Apparently, there is at least one version of cron which has somehow
escaped your wizardly notice.  Here is what "man 5 crontab" says at
my site:

     Note: the specification of days may be made  by  two  fields
     (day  of the month and day of the week).  If both are speci-
     fied as a list of elements, both are adhered to.  For  exam-
     ple,
          0 0 1,15 * 1
     would run a command on  the  first  and  fifteenth  of  each
     month,  as well as on every Monday.

Now, given a version of cron that behaves this way, one would have to
settle for a crontab entry that runs one's program every Saturday, and
have the program itself check to see whether it's the first week of
the month.

In a csh script, this can be accomplished by:

set dt= ( `date` )
if ( $dt[3] <= 7 ) then
	...
endif

In a sh script, it can be done by:

if [ `date | sed 's/^... ...  *\([^ ]*\) .*/\1/'` -le 7 ]; then
	...
fi

-- 
David Canzi
