Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


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

cron behavior



On Mon, 31 Dec 2001, will wrote:
>On Mon, 31 Dec 2001, Scott Lanning wrote:
>> I don't think there's a way to directly say
>> "every 4th Monday" (is there?), but I guess if you put
>> "day of month" to an appropriate range (22-28?) and "day of week"
>> to 1 (for Monday), then that might work.
>
>That'll have your script kick off on Mondays as well as days of the month
>22 through 28.  Cron does an or between month-days and week-days.

Out of curiosity (and a little guilt for not checking better),
here is a Perl script to exit successfully if it's the 4th Monday.
You could name it is_fourth_monday.pl and do this

    15 4 * * 1 /some/path/is_fourth_monday.pl && your_script

(I didn't test it too much, but it seems to work.)


#!/usr/local/bin/perl -w
use strict;
use Date::Manip;    # might need to install this

my ($today, $month, $year, $fourth_monday, $today_date,
    $fourth_monday_date, $which, $day);

# customizable, even -- ooooohh.. :)
$which = '4th';
$day = 'monday';

# get today's datetime
$today = ParseDate('today');

# get today's month and year to find $fourth_monday
($month, $year) = UnixDate($today, '%B', '%Y');
# get fourth Monday's datetime
$fourth_monday = ParseDate("$which $day in $month $year");

# get today's date
$today_date = UnixDate($today, '%Y%m%d');
# get 4th Monday's date
$fourth_monday_date = UnixDate($fourth_monday, '%Y%m%d');

# is today the 4th Monday?
if ($today_date eq $fourth_monday_date) {
        exit 0;
} else {
        exit 1;
}





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org