crontab syntax - Unix

This is a discussion on crontab syntax - Unix ; If you specify day of the month in a crontab then what is day of the week for? It make sense if 'day ot the month' is * then 'day of the week' can be 'every Monday. # day of ...

+ Reply to Thread
Results 1 to 16 of 16

Thread: crontab syntax

  1. crontab syntax

    If you specify day of the month in a crontab then what is day of the
    week for?
    It make sense if 'day ot the month' is * then 'day of the week' can be
    'every Monday.

    # day of the month (1-31),
    # day of the week (0-6 with 0=Sunday)

  2. Re: crontab syntax

    In article
    <72585112-d6d4-45f0-bda1-e7522ba51d90@y79g2000hsa.googlegroups.com>,
    jammer wrote:

    > If you specify day of the month in a crontab then what is day of the
    > week for?
    > It make sense if 'day ot the month' is * then 'day of the week' can be
    > 'every Monday.
    >
    > # day of the month (1-31),
    > # day of the week (0-6 with 0=Sunday)


    Suppose you have an accounting job that has to run on the last Friday of
    every month? You could code that using a range for day of month and
    weekday=5.

    Supposed you have a job that has to run on the last Friday of every
    quarter? Usually that requires coding in the script to test if the
    month is March, June, September, or December. But the scheduling for
    the last Friday of the month would be the same. The more complex
    scheduling requirements are usually done this way with the script itself
    exiting if it's not being run at the right time.

    --
    DeeDee, don't press that button! DeeDee! NO! Dee...
    [I filter all Goggle Groups posts, so any reply may be automatically by ignored]



  3. Re: crontab syntax

    On Oct 2, 5:04*pm, Michael Vilain wrote:

    > Suppose you have an accounting job that has to run on the last Friday of
    > every month? *You could code that using a range for day of month and
    > weekday=5.



    I believe that is an incorrect statement. I would refer you to the
    crontab man page that states:

    "Note that the specification of days can be made in two fields:
    monthday and weekday. If both are specified in an entry, they are
    cumulative. For example,

    0 0 1,15 * 1 command

    runs command at midnight on the first and fifteenth of each month, as
    well as every Monday.

    To specify days in only one field, set the
    other field to asterisk (*). For example,

    0 0 * * 1 command

    runs command only on Mondays."





  4. Re: crontab syntax

    jammer wrote:
    >
    > If you specify day of the month in a crontab then what is day of the
    > week for?


    If you specify either then the other does the wrong thing.
    Giving 1 for day of the month and 1 for day of the week
    will match the first of every month *and also* every Monday.
    I don't recall anyone who finds this useful behavior. It is a
    design bug converted into a feature - "What interesting
    behavior. Quick! Document it before anyone has a chance
    to call it a bug!"

    > It make sense if 'day ot the month' is * then 'day of the week' can be
    > 'every Monday.


    Correct.

    What nearly everyone seems to want it to do is filter so
    both are true. With 1 and 1 it would only trigger when the
    first of the month falls on a Monday.

  5. Re: crontab syntax

    In article
    <72585112-d6d4-45f0-bda1-e7522ba51d90@y79g2000hsa.googlegroups.com>,
    jammer wrote:

    > If you specify day of the month in a crontab then what is day of the
    > week for?
    > It make sense if 'day ot the month' is * then 'day of the week' can be
    > 'every Monday.
    >
    > # day of the month (1-31),
    > # day of the week (0-6 with 0=Sunday)


    Normally you specify either the day of the month or day of the week, and
    set the other one to *. This allows you to have either weekly or
    monthly repetitions.

    While you *can* specify both, it's an unlikely thing to want, as
    OldSchool explained.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  6. Re: crontab syntax

    In article
    ,
    Doug Freyburger wrote:

    > jammer wrote:
    > >
    > > If you specify day of the month in a crontab then what is day of the
    > > week for?

    >
    > If you specify either then the other does the wrong thing.
    > Giving 1 for day of the month and 1 for day of the week
    > will match the first of every month *and also* every Monday.
    > I don't recall anyone who finds this useful behavior. It is a
    > design bug converted into a feature - "What interesting
    > behavior. Quick! Document it before anyone has a chance
    > to call it a bug!"


    Basically it's just a missing sanity check. Unix has long had the
    philosophy that the users are supposed to be smart enough that they
    don't do dumb things like specify useless combinations of parameters.

    Once it got out this way, probably no one was willing to make an
    incompatible change to it and reject the syntax. They're probably
    worred that someone found a use for it and they don't want to break him
    for little benefit.

    >
    > > It make sense if 'day ot the month' is * then 'day of the week' can be
    > > 'every Monday.

    >
    > Correct.
    >
    > What nearly everyone seems to want it to do is filter so
    > both are true. With 1 and 1 it would only trigger when the
    > first of the month falls on a Monday.


    What people would *really* like is if 1-7 and 1 meant "first Monday of
    the month".

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  7. Re: crontab syntax

    In article
    <95540ce7-7063-4f23-99aa-1fa59424118e@j22g2000hsf.googlegroups.com>,
    OldSchool wrote:

    > On Oct 2, 5:04*pm, Michael Vilain wrote:
    >
    > > Suppose you have an accounting job that has to run on the last Friday of
    > > every month? *You could code that using a range for day of month and
    > > weekday=5.

    >
    >
    > I believe that is an incorrect statement. I would refer you to the
    > crontab man page that states:
    >
    > "Note that the specification of days can be made in two fields:
    > monthday and weekday. If both are specified in an entry, they are
    > cumulative. For example,
    >
    > 0 0 1,15 * 1 command
    >
    > runs command at midnight on the first and fifteenth of each month, as
    > well as every Monday.
    >
    > To specify days in only one field, set the
    > other field to asterisk (*). For example,
    >
    > 0 0 * * 1 command
    >
    > runs command only on Mondays."


    Actually, I use

    0 0 1-7 * 1 command

    to run a command on the first Monday of every month. Leastways, that's
    how it works on my version of crond and also the Solaris crond. If that
    doesn't work on your crond, you could code the logic in the script and
    run it daily on the first week and have it exit if the day isn't Monday.

    It seems crond isn't the same everywhere. On Solaris (which doesn't
    have syntax like "*/2") but Linux's crond does. MacOS X allows for
    extensions like @reboot, @yearly, @annually, etc. or names for days and
    months.

    So this is one case where advise from one "old school" guy may not jibe
    with what another old school guy's been doing for 20 years.

    YMMV.

    --
    DeeDee, don't press that button! DeeDee! NO! Dee...
    [I filter all Goggle Groups posts, so any reply may be automatically by ignored]



  8. Re: crontab syntax

    On 2008-10-03, Michael Vilain wrote:
    > So this is one case where advise from one "old school" guy may not jibe
    > with what another old school guy's been doing for 20 years.


    I disagree:

    man crontab

    Should always be the authoritative documentation on any system. All the
    old school guys will recommend that!

    --keith

    --
    kkeller-usenet@wombat.san-francisco.ca.us
    (try just my userid to email me)
    AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
    see X- headers for PGP signature information


  9. Re: crontab syntax

    In article ,
    Keith Keller wrote:

    > On 2008-10-03, Michael Vilain wrote:
    > > So this is one case where advise from one "old school" guy may not jibe
    > > with what another old school guy's been doing for 20 years.

    >
    > I disagree:
    >
    > man crontab
    >
    > Should always be the authoritative documentation on any system. All the
    > old school guys will recommend that!
    >
    > --keith


    Any my point was that the Solaris man page doesn't mention that syntax
    like "*/2" for specifying every 2 minutes or twice an hour (depending on
    the field). Nor does it say that specifying both day of month and day
    of week will do both. Linux kiddies are constantly posting in the
    Solaris groups whining about "Solaris is broken" because the man page
    doesn't specify the syntax that works on _their_ system for cron or date
    or find.

    Even some old hands at Solaris complain that sometimes the man page is
    wrong. It's not _always_ authoritative. Real admins look up the source
    code.

    Let's play who's the alpha geek some more...

    http://ars.userfriendly.org/cartoons/?id=20001007
    http://ars.userfriendly.org/cartoons/?id=20001009
    http://ars.userfriendly.org/cartoons/?id=20001010

    --
    DeeDee, don't press that button! DeeDee! NO! Dee...
    [I filter all Goggle Groups posts, so any reply may be automatically by ignored]



  10. Re: crontab syntax

    On Thu, 2 Oct 2008 20:15:37 -0700,
    Keith Keller wrote:
    > man crontab
    >
    > Should always be the authoritative documentation on any system. All the
    > old school guys will recommend that!


    I don't disagree, but I'll note that it's not true. The gn00 guys who
    only love formats they came up with (texinfo[1]), or people who think
    that html is teh f00ture, convert all reference material and leave you
    SOL when the graphical front-end won't start, thus depriving you of a
    browser. (Textmode browser? Not available in the standard install.)


    [1] Sure, TeX is a better typesetter than troff when you're looking to
    format, oh, _The Art of Computer Programming_. That neither means
    that requiring 100MB+ of code and data just to format the system
    documentation is a good idea, nor does it guarantee that the output
    is any better formatted than previously. And, in fact, it isn't.
    Whoever wrote that backend has all the typographic intuition of a
    six year old on ritalin. And don't get me started on the program
    called `info'. Why wasn't my favourite pager good enough?

    --
    j p d (at) d s b (dot) t u d e l f t (dot) n l .
    This message was originally posted on Usenet in plain text.
    Any other representation, additions, or changes do not have my
    consent and may be a violation of international copyright law.

  11. Re: crontab syntax

    On Oct 3, 1:10*am, Michael Vilain wrote:
    > *Linux kiddies are constantly posting in the
    > Solaris groups whining about "Solaris is broken" because the man page
    > doesn't specify the syntax that works on _their_ system for cron or date
    > or find.


    ->me<- :-)
    I am really annoyed that Solaris is often far behind the GNU
    equivalent.
    I use both Linux and Solaris and I often "dumb" down my scripts to run
    on Solaris.

  12. Re: crontab syntax

    On Oct 2, 5:59*pm, Barry Margolin wrote:

    > Basically it's just a missing sanity check. *Unix has long had the
    > philosophy that the users are supposed to be smart enough that they
    > don't do dumb things like specify useless combinations of parameters.


    That is actually funny but no doubt true.

  13. Re: crontab syntax

    Wow...all this 'cause I posted part of the man page..

    FWIW: applies at least to AIX, HPUX, DGUX (if you can find it anymore)
    and SCO (I believe).

    Can't speak to Solaris as my first job here was rolling them out the
    door....

    As for the Linux/GNU gang...they need to remember 'gnu is a recursive
    acronym, meaning "GNUs Not Unix"

    So the real answer is YMMV

    I'll see your 20 and raise you 5 BTW.

  14. Re: crontab syntax

    In article ,
    Michael Vilain wrote:

    > In article
    > <95540ce7-7063-4f23-99aa-1fa59424118e@j22g2000hsf.googlegroups.com>,
    > OldSchool wrote:
    >
    > > On Oct 2, 5:04*pm, Michael Vilain wrote:
    > >
    > > > Suppose you have an accounting job that has to run on the last Friday of
    > > > every month? *You could code that using a range for day of month and
    > > > weekday=5.

    > >
    > >
    > > I believe that is an incorrect statement. I would refer you to the
    > > crontab man page that states:
    > >
    > > "Note that the specification of days can be made in two fields:
    > > monthday and weekday. If both are specified in an entry, they are
    > > cumulative. For example,
    > >
    > > 0 0 1,15 * 1 command
    > >
    > > runs command at midnight on the first and fifteenth of each month, as
    > > well as every Monday.
    > >
    > > To specify days in only one field, set the
    > > other field to asterisk (*). For example,
    > >
    > > 0 0 * * 1 command
    > >
    > > runs command only on Mondays."

    >
    > Actually, I use
    >
    > 0 0 1-7 * 1 command
    >
    > to run a command on the first Monday of every month. Leastways, that's
    > how it works on my version of crond and also the Solaris crond.


    Interesting, what version of crond are you using? When I used to use
    Solaris (admittedly, over 5 years ago) it ran "cron", not "crond".
    Maybe you've installed a third-party replacement that implements this
    feature.

    I just checked my Ubuntu and OS X man pages, and they both describe the
    traditional behavior.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  15. Re: crontab syntax

    In article ,
    Barry Margolin wrote:

    > In article ,
    > Michael Vilain wrote:
    >
    > > In article
    > > <95540ce7-7063-4f23-99aa-1fa59424118e@j22g2000hsf.googlegroups.com>,
    > > OldSchool wrote:
    > >
    > > > On Oct 2, 5:04*pm, Michael Vilain wrote:
    > > >
    > > > > Suppose you have an accounting job that has to run on the last Friday of
    > > > > every month? *You could code that using a range for day of month and
    > > > > weekday=5.
    > > >
    > > >
    > > > I believe that is an incorrect statement. I would refer you to the
    > > > crontab man page that states:
    > > >
    > > > "Note that the specification of days can be made in two fields:
    > > > monthday and weekday. If both are specified in an entry, they are
    > > > cumulative. For example,
    > > >
    > > > 0 0 1,15 * 1 command
    > > >
    > > > runs command at midnight on the first and fifteenth of each month, as
    > > > well as every Monday.
    > > >
    > > > To specify days in only one field, set the
    > > > other field to asterisk (*). For example,
    > > >
    > > > 0 0 * * 1 command
    > > >
    > > > runs command only on Mondays."

    > >
    > > Actually, I use
    > >
    > > 0 0 1-7 * 1 command
    > >
    > > to run a command on the first Monday of every month. Leastways, that's
    > > how it works on my version of crond and also the Solaris crond.

    >
    > Interesting, what version of crond are you using? When I used to use
    > Solaris (admittedly, over 5 years ago) it ran "cron", not "crond".
    > Maybe you've installed a third-party replacement that implements this
    > feature.
    >
    > I just checked my Ubuntu and OS X man pages, and they both describe the
    > traditional behavior.


    I'm not running Solaris. And that was back in {2.[4-6],7,8} days. And
    it _was_ cron, sorry. AFAIK, if you had a special construct as part of
    RCS to specify the version of the module. ident would tell you if the
    pattern "$keyword: text $" existed in the file, be it .c, .o, or a
    program. Don't know about a stripped binary. RCS apparently added
    these. Don't know what subversion or CVS does. I never got deeply into
    a project that needed much version control and that was over 10 years
    ago anyway. GNU utilities all have "--version" or "-v".

    The MacOS X 10.4 cron function works but the periodic system maintenance
    was taken over by launchd. My crontabs still work. SuperDuper! uses
    cron to schedule it's backups. My 10.4 system has

    % ident /usr/sbin/cron
    /usr/sbin/cron:
    $FreeBSD: src/usr.sbin/cron/cron/cron.c,v 1.14 2001/03/09 03:14:09
    babkin Exp $
    $FreeBSD: src/usr.sbin/cron/cron/database.c,v 1.8 1999/08/28
    01:15:50 peter Exp $
    $FreeBSD: src/usr.sbin/cron/cron/do_command.c,v 1.20 2001/03/17
    00:21:54 peter Exp $
    $FreeBSD: src/usr.sbin/cron/cron/job.c,v 1.6 1999/08/28 01:15:50
    peter Exp $
    $FreeBSD: src/usr.sbin/cron/cron/user.c,v 1.8 1999/08/28 01:15:50
    peter Exp $
    $FreeBSD: src/usr.sbin/cron/cron/popen.c,v 1.11 2000/12/09 09:35:43
    obrien Exp $
    $FreeBSD: src/usr.sbin/cron/lib/misc.c,v 1.11 2002/08/04 04:32:27
    tjr Exp $
    $FreeBSD: src/usr.sbin/cron/lib/env.c,v 1.12 2003/02/10 11:20:58
    thomas Exp $
    $FreeBSD: src/usr.sbin/cron/lib/entry.c,v 1.12 2001/06/13 05:49:37
    dd Exp $

    --
    DeeDee, don't press that button! DeeDee! NO! Dee...
    [I filter all Goggle Groups posts, so any reply may be automatically by ignored]



  16. Re: crontab syntax

    On 2008-10-03, jpd wrote:
    >
    > I don't disagree, but I'll note that it's not true. The gn00 guys who
    > only love formats they came up with (texinfo[1]), or people who think
    > that html is teh f00ture, convert all reference material and leave you
    > SOL when the graphical front-end won't start, thus depriving you of a
    > browser.


    Ugh, thanks for the unfortunate reminder. Many of the GNU info pages
    do get converted to man pages by distro maintainers, but they aren't
    always complete.

    --keith



    --
    kkeller-usenet@wombat.san-francisco.ca.us
    (try just my userid to email me)
    AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
    see X- headers for PGP signature information


+ Reply to Thread