Yes, I know it's a limitation of cron, and that's precisely because the weekday field does not get ANDed like the other fields.
If the weekday field *was* ANDed with the other fields, it would be trivially easy to specify "third Wednesday: 0 3 15-21 * 3 /path/to/scipt.sh This would run at 3:00 AM on every day from the 15th to the 21st that happens to fall on a Wednesday. It's a 7-day span, so there will only be one Wednesday in the span, and that Wednesday would be the third Wednesday of the month. If Brian hadn't made the weekday field behave differently than the other four fields, then this would work fine. But he made an extra effort to code it differently, which breaks this use case. Since coding the weekday field differently would have taken extra time and effort, and it complicated a program written by a man whose core programming philosophy was to keep things as simple as possible, I'm led to assume that he must have had a reason to code it differently that overrode his inclination to keep the program simple and robust. As for Paul Vixie, he reimplemented cron to behave like the original AT&T cron. that Brian Kernighan wrote, so I wouldn't expect Paul to know Brian's thoughts on the matter. But Brian is still alive, as far as I know, so maybe I can track down his contact info and ask him directly. On Tue, Oct 18, 2011 at 11:50 PM, Ken D'Ambrosio <k...@jots.org> wrote: > It strikes me that this is a limitation of cron, period -- specifically, the > lack of "nth occurrence of day of week" field. Which is why the paragraph you > quoted ends "One can, however, achieve the desired result by adding a test to > the command...", said test then being illustrated: > 0 4 8-14 * * test $(date +%u) -eq 6 && echo "2nd Saturday" > > The fact that he calls it out, with an example of a work-around, makes me > think > that the historical thinking is simple: there wasn't any. It was -- at least > to Paul Vixie -- an edge case he hadn't considered when he came up with the > initial syntax for crontab, and couldn't gracefully retrofit. That being > said, > everything I just wrote is, obviously, supposition; you could ping Teh Source > [sic]; I imagine he'd enjoy a query as to his rationale: paul-at-vix-dot-com. > > -Ken > > On Tue, 18 Oct 2011 23:29:03 -0400 John Abreau <j...@blu.org> wrote > >> My experience is exactly the opposite. I've never run into a situation >> you describe, but it would be trivially easy to specify it with two >> cron entries: one specifying Mondays, and the other specifying >> the first of the month. >> >> On the other hand, my "odd case" that you claim is not particularly >> useful is one that I see all the time. Pretty much every program I've >> ever seen for scheduling events includes this, cron being the >> most notable exception. For the few others that lacked it, I recall >> reading reviews in magazines like PC World giving them bad marks >> for leaving out the feature. This leads me to believe that I'm not the >> only person on the planet who finds this functionality particularly useful. >> >> If you want other examples other than my user group, my local >> chapter of Toastmasters meets on the first and third Tuesdays >> of every month. At my previous job, we had a monthly staff meeting >> on the fourth Friday of every month. Back when the Boston Computer >> Society still existed, pretty much every BCS SIG would meet once a >> month on the n'th $WEEKDAY of the month. Doesn't GNHLUG >> also schedule its meetings in this manner? >> >> In any case, my question was about the original author's reasoning. >> I've poked around a bit more and learned that Brian Kernighan >> was the original author, but I still haven't found anything where >> he explains why he chose that behavior. >> >> Did you read somewhere that your use case was actually what >> Brian had in mind? If so, can you share a link to the article >> or point me to the book or magazine issue that you read it in? >> >> >> >> On Tue, Oct 18, 2011 at 10:45 PM, Ken D'Ambrosio <k...@jots.org> wrote: >> > Not trying to sound snooty, but this seems so obvious to me that I almost >> > wonder if I'm missing the point. All the other fields deal with different >> > units -- minutes, hours, months. day-of-month and weekday both apply to >> > days; so, if you wanted something to execute on both Mondays *and* the >> > first day of the month (say, a process that ensured that a given week/month >> > was started afresh), then you'd use both of the fields. The opposite > case, >> > where things are ANDed -- the intersection of the day of the month with the >> > day of the week -- is an odd enough set that I don't see it being >> > particularly useful. > >> > Have I, perhaps, misunderstood something? >> > >> > $.02, YMMV, etc., >> > >> > -Ken >> > >> > >> > On Tue, 18 Oct 2011 22:25:31 -0400 John Abreau <j...@blu.org> wrote >> > >> >> One thing that's always annoyed me about cron is how it handles the >> >> weekday field differently from the other fields. The first four fields, >> >> minute, hour, day-of-month, and month, are logically ANDed, but >> >> the day-of-month and weekday fields are ORed. >> >> >> >> The man page describes the behavior, but does not explain the >> >> reasoning behind it: >> >> >> >> > Note: The day of a command's execution can be specified by two >> >> > fields -- day of month, and day of week. If both fields are >> >> > restricted (ie, are not *), the command will be run when either >> >> > field matches the current time. For example, ''30 4 1,15 * 5'' >> >> > would cause a command to be run at 4:30 am on the 1st and 15th of >> >> > each month, plus every Friday. >> >> >> I've looked for an explanation for this in the past, but I've never >> >> had any luck finding one. Making this a special case makes the code >> >> needlessly more complicated and fragile, and it sacrifices useful >> >> functionality; if the weekday had been ANDed like the other fields, >> >> it would be trivially easy to specify things like "third Wednesday >> >> of the month". >> >> >> >> I'm unable to find or think of a use case that would make the special >> >> behavior useful, and I have to wonder why it was designed this way. >> >> >> >> Can anyone point me to the original author's thoughts on this? >> >> >> >> >> >> >> >> -- >> >> John Abreau / Executive Director, Boston Linux & Unix >> >> Email j...@blu.org / WWW http://www.abreau.net / PGP-Key-ID 0xD5C7B5D9 >> >> PGP-Key-Fingerprint 72 FB 39 4F 3C 3B D6 5B E0 C8 5A 6E F1 2C BE 99 >> >> _______________________________________________ >> >> gnhlug-discuss mailing list >> >> gnhlug-disc...@mail.gnhlug.org >> >> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/ >> > >> > >> > >> > >> > >> > >> >> >> >> -- >> John Abreau / Executive Director, Boston Linux & Unix >> Email j...@blu.org / WWW http://www.abreau.net / PGP-Key-ID 0xD5C7B5D9 >> PGP-Key-Fingerprint 72 FB 39 4F 3C 3B D6 5B E0 C8 5A 6E F1 2C BE 99 > > > > > > -- John Abreau / Executive Director, Boston Linux & Unix Email j...@blu.org / WWW http://www.abreau.net / PGP-Key-ID 0xD5C7B5D9 PGP-Key-Fingerprint 72 FB 39 4F 3C 3B D6 5B E0 C8 5A 6E F1 2C BE 99 _______________________________________________ Discuss mailing list Discuss@blu.org http://lists.blu.org/mailman/listinfo/discuss