For When You Can't Have The Real Thing
[ start | index | login ]
start > Linux > cron > running every second Friday

running every second Friday

Created by dave. Last edited by dave, 10 years and 192 days ago. Viewed 4,454 times. #1
[edit] [rdf]
labels
attachments

Problem

I have a function that I want to run on the second and fourth fridays of a month. So I craft my crontab entry like this:

5 21 8,9,10,11,12,13,14,22,23,24,25,26,27,28 * 5 /usr/local/sbin/command

...which I think is supposed to mean "run at 21:05, if the day of the month is one of (8-14 or 22-28), and the month of the year is any month, and the day of the week is Friday".

However, my crontab is being run if the day of the month is (8-14 or 22-28), no matter what the day of the week is.

What did I do wrong?

Observation

This a little snip-it from the man pages:

Example 3: Specifying days of the month and week

This example

0 0 1,15 * 1

would run a command on the first and fifteenth of each month, as well as on every Monday.

To specify days by only one field, the other field should be set to *. For example:

0 0 * * 1

would run a command only on Mondays.

What I think I get from that is that you will have no choice but to run it every Friday.

Solution

Check which day of the week it is when cron goes to run the command.

5 21 8-14,22-28 * * [ `date +%a` = Fri ] && /usr/local/sbin/command
no comments | post comment
This is a collection of techical information, much of it learned the hard way. Consider it a lab book or a /info directory. I doubt much of it will be of use to anyone else.

Useful:


snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt