[ale] cron entry that runs the 2nd saturday of every month
Michael H. Warfield
mhw at WittsEnd.com
Fri Aug 26 18:45:52 EDT 2011
On Fri, 2011-08-26 at 16:47 -0400, Erik Mathis wrote:
> I ran into this same issue, and iirc cron uses a AND to compare dates.
> I ended up running it every Monday and added a wrapper to the script
> to decide if its the right day to do this function. If not, just exit.
No, there's a gotcha in there. It uses "AND" to compare time and then
only one of two particular fields (day of month or day of week) have to
be true, so that's an OR. That's a PITA.
From "man 5 crontab":
==
Note: The day of a command's execution can be specified in the follow‐
ing two fields — 'day of month', and 'day of week'. If both fields are
restricted (i.e., do not contain the "*" character), the command will
be run when either field matches the current 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.
==
The exact opposite of what you want.
I actually have a more complex example that would work if it truly WAS
an AND (and I can think of no useful reason for it being an OR but it
is).
Real world situation. I have a meeting to take place to take on the
Wednesday following the 2nd Tuesday. Notice that it is NOT the the
second Wednesday. One Wednesday out of every 7 will be the third
Wednesday. So I would need a Wednesday that's on 9-15 (15 being the 3rd
Wednesday with 1 and 8 being the first two). An AND condition would be
perfect. Tis not to be. Thou must script.
> -Erik-
Regards.
Mike
> On Fri, Aug 26, 2011 at 4:27 PM, Geoffrey Myers
> <lists at serioustechnology.com> wrote:
> > Lightner, Jeff wrote:
> >> But the OP wanted 2nd Saturday only. The +%u just tells you it is
> >> Saturday - not which Saturday.
> >
> > I am the op. Using the combination of the day of the week and the day
> > of the month you can calculate whether its the 2nd Saturday of the month
> > or not.
> >
> >>
> >> I had tested for it being Saturday in my 2008 script but if the cron
> >> job only runs on Saturday it isn't really necessary. (My test was
> >> to prevent someone from just moving the cron job without
> >> understanding its purpose.)
> >>
> >> -----Original Message----- From: ale-bounces at ale.org
> >> [mailto:ale-bounces at ale.org] On Behalf Of Geoffrey Myers Sent:
> >> Friday, August 26, 2011 3:39 PM To: Atlanta Linux Enthusiasts
> >> Subject: Re: [ale] cron entry that runs the 2nd saturday of every
> >> month
> >>
> >> 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
> >>
> >>> You put your script to compare day of month with the output of the
> >>> cal line and run the desired command if they match. Then your
> >>> cron entry runs EVERY Saturday and the script determines whether to
> >>> run the commands you want based on whether it is the 2nd Saturday.
> >>>
> >>> There may be easier ways to do this on Linux but I figured I'd send
> >>> you this at least as a basis for thought.
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> -----Original Message----- From: ale-bounces at ale.org
> >>> [mailto:ale-bounces at ale.org] On Behalf Of Geoffrey Myers Sent:
> >>> Friday, August 26, 2011 2:26 PM To: Atlanta Linux Enthusiasts
> >>> Subject: [ale] cron entry that runs the 2nd saturday of every month
> >>>
> >>>
> >>> Is it possible?
> >>>
> >>> -- Until later, Geoffrey
> >>>
> >>> "I predict future happiness for America if they can prevent the
> >>> government from wasting the labors of the people under the pretense
> >>> of taking care of them." - Thomas Jefferson
> >>> _______________________________________________ Ale mailing list
> >>> Ale at ale.org http://mail.ale.org/mailman/listinfo/ale See JOBS,
> >>> ANNOUNCE and SCHOOLS lists at http://mail.ale.org/mailman/listinfo
> >>>
> >>>
> >>>
> >>> Proud partner. Susan G. Komen for the Cure.
> >>>
> >>>
> >>> Please consider our environment before printing this e-mail or
> >>> attachments.
> >>>
> >>> ---------------------------------- CONFIDENTIALITY NOTICE: This
> >>> e-mail may contain privileged or confidential information and is
> >>> for the sole use of the intended recipient(s). If you are not the
> >>> intended recipient, any disclosure, copying, distribution, or use
> >>> of the contents of this information is prohibited and may be
> >>> unlawful. If you have received this electronic transmission in
> >>> error, please reply immediately to the sender that you have
> >>> received the message in error, and delete it. Thank you.
> >>> ----------------------------------
> >>>
> >>> _______________________________________________ Ale mailing list
> >>> Ale at ale.org http://mail.ale.org/mailman/listinfo/ale See JOBS,
> >>> ANNOUNCE and SCHOOLS lists at http://mail.ale.org/mailman/listinfo
> >>
> >>
> >
> >
> > --
> > Until later, Geoffrey
> >
> > "I predict future happiness for America if they can prevent
> > the government from wasting the labors of the people under
> > the pretense of taking care of them."
> > - Thomas Jefferson
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://mail.ale.org/mailman/listinfo/ale
> > See JOBS, ANNOUNCE and SCHOOLS lists at
> > http://mail.ale.org/mailman/listinfo
> >
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
--
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/79a4d016/attachment-0001.bin
More information about the Ale
mailing list