Re: Scheduling Jobs - Last day of the month - HOWTO?



On 2006-08-30, Michal Vojan wrote:
Chris F.A. Johnson wrote:

On 2006-08-30, Michael B Johnson wrote:
I would like to schedule a job on the last day of each month.

When I looked through the man pages for Cron, there did not appear to be
any obvious mechanism for specifying the *last day* of the month.

Unfortunately, my environment is Cygwin, and the job to be launched
(executable) was written in Visual Basic 6. I have access to "bash" via
cygwin, as well as perl and awk.


0 0 31 1,3,5,7,8,10,12 * /path/to/script
0 0 30 9,4,6,11 * /path/to/script
0 0 28,29 2 * /path/to/wrapperscript

In the wrapperscript, called only in February, check whether the
current year is a leap year:

eval "$(date "$@" "+year=%Y day=%d)"
case $year in
*0[48] |\
*[2468][048] |\
*[13579][26] |\
*[02468][048]00 |\
*[13579][26]00 ) [ ${day#0} -eq 29 ] && /path/to/script ;;
*) [ ${day#0} -eq 28 ] && /path/to/script ;;
esac

[please don't top post]

I don't know exactly what your script is supposed to do

The script is run on the 28th and 29th of each February (by the
third crontab line above). It checks whether the current year is a
leap year. If it is a leap year, and the date is the 29th, or if it
is not a leap year, and the date is the 28th, then it calls the
payload script.

but wouldn't that be better to run the script on the first day of
each month?

That's a day late.

When there is some operation which is date related just subtract one
day, omit data from current day, etc. I find it better than think of
those weird inteligentlike constructions.

Your suggestion sounds much more complicated.

Please, no offence, Chris. I just think that such scripts are often
sources of problems.

The code that tests for the leap year has been thoroughly tested.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.



Relevant Pages

  • Re: Need cron formula
    ... many days in the current month, leap years, etc. I've read that there ... Tell cron to execute a script at 3:00 am every day. ... it is the 25th day it executes the command, ...
    (comp.unix.programmer)
  • Re: How to resolve timestamp?
    ... Finally an answer to this mystery! ... I'm not Herb, ... mind you have to add the Leap Days in Leap Years. ... make a script out of this, your script will have to add the ...
    (microsoft.public.windows.server.dns)
  • Re: Problem with count-up script
    ... > still has a problem calculating the number of months. ... Sorry, sorry, sorry if it's your script. ... exactly true. ... The common formula for leap year (accounting also the ...
    (comp.lang.javascript)
  • Re: Need cron formula
    ... many days in the current month, leap years, etc. I've read that there ... is no way that cron can do this by itself but must run an external ... script, perhaps once each day. ... The system crashes in the brief interval between starting the at ...
    (comp.unix.programmer)
  • Re: Calculating age of death
    ... <way more so than simply specifying years and days,> ... | "rough" indicator of time span, this if fine; ... | the inaccuracy introduced by the leap years here). ...
    (microsoft.public.excel.worksheet.functions)