cron for 4th sunday every month?

Linux & Unix newsgroup archiveAix2004

Linuxmisc » Aix

Gerard MacNei #1 / 10 Tue, 09 Mar 2004 23:01:08 GMT
What would the crontab entry be to run a script on the 4th sunday every
month?

Thanks

--
-----------------------------------------------------------------
Gerard MacNeil                           Voice 902 888 4316
M.F. Schurman Company, Ltd.    Fax    902 436 4044
http://www.**-**.com/
gera...@schurmans.com
-----------------------------------------------------------------

F. Michael Or #2 / 10 Wed, 10 Mar 2004 01:28:15 GMT
news:UCIq7.54$hB4.10114@sapphire.mtt.net...

You cannot do it directly via cron.  What you can do is to run the script
every Sunday, and decide inside the script whether or not it is the 4th
Sunday.  If you have perl on your system, the following should work under
ksh:

if [ `perl -e 'use POSIX;@datearr = localtime;\
print POSIX::ceil($datearr[3] / 7);'` -ne 4 ]; then
   exit 0
fi
#
# Getting here means it is the fourth Sunday.
#
...

This technique is useful because it can be applied to any day of the week.

HTH

holman_ #3 / 10 Wed, 10 Mar 2004 02:42:07 GMT

Looking at the calendar the 4th Sunday is always between 22-28th so
how about having cron run this script every day:

#!/bin/ksh
DOW=`date +%a`   # Day Of Week (Sun, Mon, etc)
NDM=`date +%d`   # Number of day in the Month (01, 02, etc)

if [ "$NDM" -ge "22" -a "$NDM" -le "28" -a "$DOW" = "Sun" ]
then
        # Put script to run on 4th sunday here        
fi

HTH!!

Yale Shafe #4 / 10 Thu, 11 Mar 2004 11:15:14 GMT

don't use crontab use the 'at'  command

when calculating the date of the 4th sunday  of the month for resubmission
try something like this:

cal $targetmonth $targetyear | sed 1,2d | cut -c1-2 | grep .[0-9] | sed
4!d

adjusting the cut will enable the use of different days of the week and
the final sed deletes every thing except the nth line

Jan-Frode Myklebu #5 / 10 Sat, 13 Mar 2004 23:05:22 GMT
On 21 Sep 2001 11:42:07 -0700, holman_sh <holman...@my-deja.com> wrote:

or put this info directly into the crontab:

1 1 22-28 * 7 /script/to/run

 -jf

Matthew Land #6 / 10 Sun, 14 Mar 2004 01:27:27 GMT

No, you have that wrong.  The cron time stamps are OR statements NOT
AND statements.  This will run on the 22, 23, 24, 25, 26, 27, 28, and
EVERY sunday.

I usually do this by cronning the job for every sunday, and have the
script (or build a frontend) to do a "4th" sunday check before continuing
to process the necessary info.

 - Matt

--
_______________________________________________________________________
Matthew Landt -  AIX and HACMP Cert. Specialist  - la...@austin.ibm.com
  IBM High Speed Interconnect - Fibre Channel I/O Dev/Test/Support
   << Comments, views, and opinions are mine alone, not IBM's. >>

sp2 admi #7 / 10 Mon, 15 Mar 2004 04:26:53 GMT
that would not work right. it would execute the script on every sunday, as well
as every day between 22 and 28.
sp2 admi #8 / 10 Mon, 15 Mar 2004 23:52:09 GMT

read the man pages as follows.. and also, stop poting in html!

    Note: Any character preceeded by a backslash (including the %) causes that
    character to be treated literally. The specification of days may be made by
    two fields (day of the month and day of the week). If you specify both as a
    list of elements, both are adhered to. For example, the following entry:
    0 0 1,15 * 1 command

    would run command on the first and fif{*filter*}th days of each month, as well as
    every Monday. To specify days by only one field, the other field should
    contain an * .

Matthew Land #9 / 10 Mon, 15 Mar 2004 23:10:15 GMT

Ah. that's true.  It is for the "day of the week" portion only.

Thanks for catching that.

 - matt
--
_______________________________________________________________________
Matthew Landt -  AIX and HACMP Cert. Specialist  - la...@austin.ibm.com
  IBM High Speed Interconnect - Fibre Channel I/O Dev/Test/Support
   << Comments, views, and opinions are mine alone, not IBM's. >>

Dan Goodma #10 / 10 Wed, 24 Mar 2004 00:26:19 GMT

True. But you could have a script which runs every Sunday, and which
executes the 4th Sunday only code only when a certain expression is
true.

For a cool algorithm which purports to calculate whether or not a day of
the week is the nth such day of the week in a month, check out:

http://www.smart.net/~mmontes/ushols.html#ALG

I have not tested this yet, but it looks like it would do the job.

Dan Goodman
Senior Systems Specialist
Thomas Jefferson University Hospital

This page is kept from the Linuxmisc archive of Linux and Unix newsgroups (snapshot 2013). Posts are shown as they were published, so commands, versions and addresses date from the original discussion. Linuxmisc.com now publishes a guide to online casinos in Canada.