On Fri, Sep 02, 2011 at 03:19:31PM +0800, jida...@jidanni.org wrote:
> Package: cron
> Version: 3.0pl1-119
> Severity: wishlist
> File: /usr/share/man/man5/crontab.5.gz
> 
> Gentlemen, you provide
>        # Run on every second Saturday of the month
>        0 4 8-14 * *    test $(date +%u) -eq 6 && echo "2nd Saturday"
> however you sidestep 'last', e.g., every last Tuesday of the month.

There's no way to define that in crontab semantics AFAIK. You would have to
implement that kind of check in the cron task itself.

> So please add an example, e.g.,
>        0 4 * * 2 echo -e TueLast\\tLast Tuesday of the month|calendar -f 
> /dev/stdin

Sorry, I'm afraid this example is not correct. It would run every Tuesday. A
more approximate example could be this:

        0 4 21-31 * *    test $(date +%u) -eq 6 && echo "Last Saturday"

But unfortunately, it could actually trigger *twice* in the same month for
some months (depending on where the last Saturday "falls"). 

A more exact, and convoluted, example would require the cron script to
checkout the output of 'ncal'.  Something along the lines of this:

        0 4 * * Sat   [ "$(date +%e)" = "`ncal | grep $(date +%a | sed  -e 
's/.$//') | sed -e 's/^.*\s\([0-9]\+\)\s*$/\1/'`" ] && echo "Last Saturday"

Note: Not fully tested.

The check basicly will compare the current day of the month to the *last* day
as shown in ncal's output for the present month.

As you can see, this is a quite complex example, I don't think it is worth
dropping it in the manpage. 

The manpage can document that more complex checks would have to be
implemented in the cron task itself since the cron semantics are limited.

Regards

Javier

Attachment: signature.asc
Description: Digital signature

Reply via email to