[CentOS] crontab
Brian Mathis
brian.mathis+centos at betteradmin.com
Thu Jul 7 13:21:10 UTC 2011
On Thu, Jul 7, 2011 at 7:48 AM, Helmut Drodofsky
<drodofsky at internet-xs.de> 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 ❧-
More information about the CentOS
mailing list