Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Jun 2009 10:36:09 -0400
From:      Paul Chvostek <paul+fbsd@it.ca>
To:        Jos Chrispijn <jos@webrz.net>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: Cronjob
Message-ID:  <20090608143609.GA5108@it.ca>
In-Reply-To: <4A2D0A5C.8010809@webrz.net>
References:  <4A2D0A5C.8010809@webrz.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Jos,

On Mon, Jun 08, 2009 at 02:55:56PM +0200, Jos Chrispijn wrote:
> 
> I would like to execute a script on every last day of the month in my 
> crontab.
> Can someone tell me how I should solve that as it doesn't know which 
> month day is the last day of the month?
> Solving this in the script to be executed is no option.

The only solutions I see are the three-cronjob approach:

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

Alternately, you could do this with a single cronjob by putting a little
scripting intelligence into the crontab itself:

  0 1 28-31 * * test `date -v+1d '+%d'` -eq 1 && /path/to/script

That may be your easiest option.  The script only gets run on the
correct dates, but the cron job still gets run more frequently.

p

-- 
  Paul Chvostek                                             <paul@it.ca>
  it.canada                                            http://www.it.ca/




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090608143609.GA5108>