Cron - First Saturday of the month

David Canzi dmcanzi at watserv1.waterloo.edu
Thu Aug 9 07:45:39 AEST 1990


In article <1990Aug8.185745.16606 at iwarp.intel.com> merlyn at iwarp.intel.com (Randal Schwartz) writes:
>In article <19744 at orstcs.CS.ORST.EDU>, curt at 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



More information about the Comp.unix.wizards mailing list