[ale] cron entry that runs the 2nd saturday of every month

Michael H. Warfield mhw at WittsEnd.com
Fri Aug 26 20:00:54 EDT 2011


On Fri, 2011-08-26 at 19:55 -0400, Michael H. Warfield wrote: 
> On Fri, 2011-08-26 at 19:33 -0400, David Tomaschik wrote: 
> > On 08/26/2011 03:38 PM, Geoffrey Myers wrote:
> > > Lightner, Jeff wrote:
> > >> When I had to do this back in 2008 on HP-UX I worked out a script
> > >> that relied on the cal (calendar) command.
> > >>
> > >> The following command line will give you the 2nd Saturday of the
> > >> month:
> > >>
> > >> cal |cut -c19-20 |grep '[0-9]'|head -2 |tail -1
> > >>
> > >> The following command will give you today's day of month: date +%d
> > > Doing something similar only relying on date alone:
> > >
> > > date +%d
> > > date +%u

> > If you have cron run every Saturday, the %u is unnecessary.  (You know
> > it's Saturday.)  Then just compare to the range [8-14].  No cal needed. 
> > (Might be what you're doing already.)

> Even when you KNOW it's best to CONFIRM.

> Short cut...

> CODE=`date +%u%d`

> if [[ $CODE -gt 607 && -lt 615 ]]

Ok, ok...  Before anyone jumps on me for the syntax error...

if [[ ${CODE} -gt 607 && ${CODE} -lt 615 ]]

I saw it when I sent it.  Too late.  Sigh...

> then
> # Do it.
> else
> # Don't do it..
> fi
> 
> If it's not on Saturday, the test fails.  If it is on Saturday (%u = 6)
> then the day has to be between 07 and 15.
> 
> Seems simple enough to me.
> 
> Regards,
> Mike

-- 
Michael H. Warfield (AI4NB) | (770) 985-6132 |  mhw at WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 482 bytes
Desc: This is a digitally signed message part
Url : http://mail.ale.org/pipermail/ale/attachments/20110826/b673167e/attachment-0001.bin 


More information about the Ale mailing list