This as ugly as heck - but it does the job for us - we have a set of
schedules that are 'first Friday of month is full, and the day after
that is an incremental' so this bit of embarrasingly unprofessional
perl code does that for me...
WARNING - if you disable the DEBUG line and run this it will immediately
without prompting overwrite three schedules called Monthly Weekly and
Daily.
#!/bin/perl
#
#comment out the DEBUG line to make it do something...
$DEBUG=1;
$MonthlySched="Monthly";
$WeeklySched="Weekly";
$DailySched="Daily";
$FridayLevel="full";
$SaturdayLevel="incr";
use Time::Local;
$day=86400;
# set up time of first day of current month
(@now)=localtime();
$time=timelocal(0,0,1,1,$now[4],$now[5]);
#$time=timelocal(0,0,1,1,0,2005);
die "must specify server name: setmonthly {servername}\n" unless
($ARGV[0]);
$SERVER=$ARGV[0];
$monthlyoverride='';
$weeklyoverride='';
#build the override strings.
#
while (1) {
($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($time);
if(($wday==5)&&($mon !=$lastmon)) {
$year +=1900;
$lastmon=$mon;
$mon++;
$nday=($mday+1);
$monthlyoverride .= "$FridayLevel $mon/$mday/$year,
$SaturdayLevel $mon/$nday/$year,\n";
$weeklyoverride .= "skip $mon/$mday/$year, skip
$mon/$nday/$year,\n";
$time += (20*$day);
}
$time += $day;
last if ($year == $now[5]+5); #5 years from now.
}
chop $weeklyoverride;
chop $monthlyoverride;
chop $weeklyoverride;
chop $monthlyoverride;
$updatescript=". type: NSR Schedule;
name: $WeeklySched
update override: $weeklyoverride
. type: NSR Schedule;
name: $MonthlySched
update override: $monthlyoverride
";
if($DEBUG) {
print $updatescript;
print "DEBUG mode: no changes made\n";
}
else {
##firstly make sure all the schedules exist.
$script="create type: NSR schedule;
name: $MonthlySched;
period: Month;
action: \"skip skip skip skip skip skip skip skip skip skip skip skip
skip skip skip skip skip skip skip skip skip skip skip skip skip skip
skip skip skip skip skip \";
override:
create type: NSR schedule;
name: $DailySched;
comment: ;
period: Week;
action: \"incr incr incr incr incr skip skip \";
create type: NSR schedule;
name: $WeeklySched;
comment: ;
period: Week;
action: \"skip skip skip skip skip $FridayLevel $SaturdayLevel \";
override:
";
if($DEBUG) {
print $script;
print "DEBUG mode: no changes made\n";
}
else {
open NSRADMIN, "echo '$script' | nsradmin -s $SERVER -i - 2>&1|"
or die "$!: error";
while (<NSRADMIN>) {
}
close NSRADMIN;
}
# now update with override strings
open NSRADMIN, "echo '$updatescript' | nsradmin -s $SERVER -i -
2>&1|" or die "$!: error";
while (<NSRADMIN>) {
print;
}
close NSRADMIN;
}
NOTICE
This e-mail and any attachments are confidential and may contain copyright
material of Macquarie Bank or third parties. If you are not the intended
recipient of this email you should not read, print, re-transmit, store or act
in reliance on this e-mail or any attachments, and should destroy all copies of
them. Macquarie Bank does not guarantee the integrity of any emails or any
attached files. The views or opinions expressed are the author's own and may
not reflect the views or opinions of Macquarie Bank.
To sign off this list, send email to listserv AT listserv.temple DOT edu and
type "signoff networker" in the
body of the email. Please write to networker-request AT listserv.temple DOT edu
if you have any problems
wit this list. You can access the archives at
http://listserv.temple.edu/archives/networker.html or
via RSS at http://listserv.temple.edu/cgi-bin/wa?RSS&L=NETWORKER
|