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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20110707/b2442ed4/attachment-0002.html>
Helmut Drodofsky 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!not ignoring, OR-ing: $ man 5 crontab <snip> 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, aren?t *), 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. <snip> don't know if there's a cleaner solution than using only eg saturday in cron and having a wrapper script for your program to check that it's the first week of a month.
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? > > HelmutThe 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 ?-