cron for 4th sunday every month?
Linuxmisc » Aix
month?
Thanks
--
-----------------------------------------------------------------
Gerard MacNeil Voice 902 888 4316
M.F. Schurman Company, Ltd. Fax 902 436 4044
http://www.**-**.com/
gera...@schurmans.com
-----------------------------------------------------------------
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
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!!
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
or put this info directly into the crontab:
1 1 22-28 * 7 /script/to/run
-jf
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. >>
as every day between 22 and 28.
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 * .
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. >>
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