[Summary] will crontab entry run if less than 31 days in month

From: Greg Rahn <RAHN_at_uwplatt.edu>
Date: Wed, 06 Mar 1996 08:48:39 -0600 (CST)

My original question:

>If I want to run a crontab the last day of the month and I put 31 in for the
>day of the month field, will the job still run if there are only 30 days in
>that month or 28 or 29 days...see where I am going.

Well, attached are the comments I received. To make a long story short, it
will not run on months with less than 31 days. Here are some of the
suggestions to overcome the problem though.
------------------------------------------------
Greg Rahn Student Systems Management Assistant
Office of Information Technology, UW-Platteville
rahn_at_uwplatt.edu http://www.uwplatt.edu/~rahn
------------------------------------------------
/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\
From: IN%"berc_at_pa.dec.com"

Start a script every day that checks if the current date + 24 hours
is the next month, and if so fires off your job. Should be < 50
lines of C, also doable in Perl, etc.
/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\
From: IN%"awagliar_at_vt.edu"

Since not even VixieCron supports something like an "L" in the third (day
of the month) column, you're only options are either:

1) if it's feasible, run the command at the first minute of the first day
   of every month. However, I get the feeling that it's necessary for you
   to run it at the end of a particular month.

2) set up the crontab entries in the following way (for example, to run
   the shell script Command at 10pm on the last day of every month):

# 10pm on the 31st of January, March, May, July, August, October, and December
0 22 31 1,3,5,7,8,10,12 * sh Command
# 10pm on the 30th of April, June, September, and November
0 22 30 4,6,9,11 * sh Command

As for February, you could either run it always on the 28th:

# 10pm on the 28th of February
0 22 29 2 * sh Command

Or it will run twice that year:

# 10pm on the 29th of Febraury, if it exists
0 22 29 2 * sh Command
# 10pm on the 28th of February
0 22 29 2 * sh Command

Or you could write a wrapper script for February that would check to see
if the year is a multiple of four or someusch like that. Sorry I couldn't
be of more help, but that's all I could think of at the moment. Good
luck...
/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\
From: IN%"reeves_at_zk3.dec.com" "Jon Reeves"

Not aware of anything (and I even looked at Vixie cron), but you might try
running it on 28-31 and putting a check to see if this is the last day of
the month, then exiting if it isn't.
/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\
From: IN%"dgj_at_omega.rtpnc.epa.gov" "Doug Gould"

why not run your cron job at 00:01 on the 1st ?
/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\
From: IN%"jnolan_at_ibm.net"

No it will only run on the 31st.
/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\
From: IN%"Jonathan.Buchanan_at_ska.com" "Jon Buchanan"
             
Don't think you can solve your cron requirement with just one cron
entry, but you can maybe do it with three as follows:

00 01 31 1,3,5,7,8,10,12 * my_job
00 01 30 4,6,9,11 * my_job
00 01 28 2 * my_job

Lets take the DEC approach and forget about leap years since there won't
be another for 4 years!

However, test it. If you were to include a particular weekday (eg, to
run the job on the last Friday of each month) then it probably wouldn't
work, because contrary to the crontab man page it seems that cron does
an OR on the date/day fields instead of an AND - shame.
/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\
From: IN%"Knut.Hellebo_at_nho.hydro.com"

No. You'll have to write a wrapper. One possibility is to let the wrapper
start the 28th (there cannot be less than 28 days in a month, hopefully) and
do a test to see whether the following day(s) are in the next month and if
they are, reschedule by using 'at'.
/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\-/-\
Received on Wed Mar 06 1996 - 16:23:16 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT