Re: Scheduling Jobs - Last day of the month - HOWTO?
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Wed, 30 Aug 2006 17:13:07 -0400
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
.
- References:
- Scheduling Jobs - Last day of the month - HOWTO?
- From: Michael B . Johnson
- Re: Scheduling Jobs - Last day of the month - HOWTO?
- From: Chris F.A. Johnson
- Re: Scheduling Jobs - Last day of the month - HOWTO?
- From: Michal Vojan
- Scheduling Jobs - Last day of the month - HOWTO?
- Prev by Date: Re: Scheduling Jobs - Last day of the month - HOWTO?
- Next by Date: Re: Scheduling Jobs - Last day of the month - HOWTO?
- Previous by thread: Re: Scheduling Jobs - Last day of the month - HOWTO?
- Next by thread: Re: Scheduling Jobs - Last day of the month - HOWTO?
- Index(es):
Relevant Pages
|