Re: cron processes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Cameron Simpson wrote:
> 
> On 02Feb2007 15:54, Rick Stevens <rstevens@xxxxxxxxxxxxxxx> wrote:
> | On Fri, 2007-02-02 at 14:09 -0800, bruce wrote:
> | > i can setup a cron process to run on a daily/weekly/monthly periodic
> | > frequency. however, if i'm in jan, and i setup a cron to run on a monthly
> | > basis, starting on jan 29, what happens when the os gets to feb 28, and
> | > there is no feb 29?
> | 
> | I believe it'll run on March 1, but I won't swear to it.  Why not choose
> | a day you KNOW occurs (such as the 14th).
> 
> I think in fact it simply won't run because that date will not occur.
> 
> If you want 'end of month' stuff you either run it on the first of the
> month, or every day and have your cron job check if it's the last day of
> the month.
> -- 

Cameron is correct.  If you set up something to run at noon on the 29'th
of the month, it'll only be started 11 times a year.

Output from "man 5 crontab" (near the bottom) sez:
> 
>   These special time specification "nicknames" are supported, which replace
>   the 5 initial time and date fields, and are prefixed by the '@' character:
>   @reboot    :    Run once, at startup.
>   @yearly    :    Run once a year, ie.  "0 0 1 1 *".
>   @annually  :    Run once a year, ie.  "0 0 1 1 *".
>   @monthly   :    Run once a month, ie. "0 0 1 * *".
>   @weekly    :    Run once a week, ie.  "0 0 * * 0".
>   @daily     :    Run once a day, ie.   "0 0 * * *".

Keeping in mind that the first 5 fields in a crontab represent Minute,
Hour, Day-of-Month, Month, Day-of-Week (which I have to look up every
time I deal with cron), you see that all of the "@" fields translate to
"the first chance you get during the period".

Had Paul Vixie put a little more thought into it, he might have allowed
non-positive numbers to represent sub-units back from the end of a
period; I.e.: "-1 0 0 0 *" == December 31'st at 23:58.  BUT he didn't
(except for days of the week, wherein "0" and "7" both mean Sunday).

So you're basically stuck with something like Cameron suggested:  if you
want 'end of month', either do it on the 1st, or run the job every day,
and only have it do useful stuff on the last day of any particular month.

On the other hand, you could use at(1) and get cute with the date string
by "backing up" from the 1st of the next month.  I.e.: a shell script
which, once handed to at(1) would run at 12:34pm on the last day of any
month _and_ when finished, reschedule itself for the following month.
The key to getting this to happen correctly can be found in the output of:

	sos=> date -d "Jan 01 2007 12:34 1 day ago"
	Sun Dec 31 12:34:00 CST 2006
	sos=> 

BTW: Time arguments to at(1) DO NOT match the "normal" output of date(1),
so be careful how you specify 'em.

Hope this helps,

-S


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux