How to cron?

RTFM is not the best answer …

man crontab
SunOS 5.10 Last change: 10 Nov 2005

User Commands crontab(1)
A crontab file consists of lines of six fields each. The
fields are separated by spaces or tabs. The first five are
integer patterns that specify the following:

minute (0-59),
hour (0-23),
day of the month (1-31),
month of the year (1-12),
day of the week (0-6 with 0=Sunday).

so far so good. But read this

Each of these patterns can be either an asterisk (meaning
all legal values) or a list of elements separated by commas.
An element is either a number or two numbers separated by a
minus sign (meaning an inclusive range). Time specified here
is interpreted in the timezone of the cron(1M) daemon, which
is set system-wide in /etc/default/init. Entries do not use
the invoking user's timezone. The specification of days can
be made by two fields (day of the month and day of the
week). Both are adhered to if specified as a list of ele-
ments. See .

See .

Let’s imagine you want to run a job today, Thursday May 15, 2008 at 2:15pm
You write:
15 14 15 05 4 /tmp/run-my-job

The job will be run Today at 2:15, next year Friday May 15, 2009 at 2:15pm and next week Thursday May 22, 2008 at 2:15pm…

The correct method is to use
15 14 15 05 * /tmp/run-my-job

Specifying both day of week and day of month is not what I expected 😈

3 thoughts on “How to cron?

  1. Robert V


    15 14 15 05 4 /tmp/run-my-job

    Should run only when the 15th of may is a Thursday, not every year! It should never run on a Friday. Did I misunderstand what you’re saying?

  2. Laurent Schneider Post author

    try it!

    15 14 15 05 4 /tmp/run-my-job

    15th of month OR 4th day of week

    (it is a OR not a AND)

    that’s the point, I expected a 15th AND Thursday but it is 15th OR Thursday

  3. Pingback: use cron to schedule a job only once | Laurent Schneider

Leave a Reply

Your email address will not be published.