[PLUG] cron on first tuesday or last friday of the month?

Shannon C. Dealy dealy at deatech.com
Sat Aug 17 17:25:07 UTC 2002


On Sat, 17 Aug 2002, Richard Seymour wrote:

> Can cron jobs be configured to run on the Nth specific weekday of each
> month?
[snip]

It's a little convoluted, but you could run a cronjob on the 14th of the
month which would launch an "at" command to run on the next occurance of
the day of the week you are interested in.

> Besides the Nth specific weekday problem, I also need to be able to run
> jobs on the last specific weekday, which will be either the fourth or
> the fifth, depending on the calendar.
[snip]

For this one, the easiest ways I can come up with are:

1-Use cron to run a shell script every week on the day of the week you are
  interested in, then have the script test for whether or not it is the
  day you want by checking if there are at least seven more days left in
  the month, and if there aren't, then run the job you are interested in.

2-Use an approach similar to the one for your first question, but
  using multiple crontab entries, one for months that have 31 days, one
  for months with 30 days, and one or two for February (not quite sure how
  to handle leap years), set the entries to launch an "at" command to run
  on the next occurance of the day of the week you want, one week before
  the end of the month for each of these.


Shannon C. Dealy      |               DeaTech Research Inc.
dealy at deatech.com     |          - Custom Software Development -
                      |    Embedded Systems, Real-time, Device Drivers
Phone: (800) 467-5820 | Networking, Scientific & Engineering Applications
   or: (541) 451-5177 |                  www.deatech.com





More information about the PLUG mailing list