Re: crontab

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



On Thu, Jul 7, 2011 at 7:48 AM, Helmut Drodofsky
<drodofsky@xxxxxxxxxxxxxx> wrote:
> I would like to run a program at 2:35 at the first Saturday of each odd
> month.
>
> My solution:
>
> 35 2 1-7 1,3,5,7,9,11 6 /bin/program
>
> The program was executed yesterday = Wednesday = day 3,  cron ignores the
> day of the week!
>
> Is there a solution with cron – or have I to write a script to check the
> date?
>
> Helmut



The most elegant way I have seen to do this is:

    35 2 1-7 1,3,5,7,9,11 * [ "$(date '+\%a')" == "Sat" ] && command

This will run on the 1st through 7th days of the month, and if the day
(as returned by "date +%a") is Sat, then execute the command.
Otherwise do nothing.

I might also replace the month numbers with names, just to make it
easier to understand (though the lines will get long):

    35 2 1-7 Jan,Mar,May,Jul,Sep,Nov * [ "$(date '+\%a')" == "Sat" ] && command


-☙ Brian Mathis ❧-
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos



[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux