version 1.1, 2004/06/23 14:41:38
|
version 1.2, 2010/05/23 16:07:09
|
Line 38 http://www.lon-capa.org/
|
Line 38 http://www.lon-capa.org/
|
if (-e '/etc/cron.d/loncapa.lpmlsave') { |
if (-e '/etc/cron.d/loncapa.lpmlsave') { |
unlink ('/etc/cron.d/loncapa.lpmlsave'); |
unlink ('/etc/cron.d/loncapa.lpmlsave'); |
} |
} |
|
print "\nUpdating /etc/cron.d/loncapa configuration file\n"; |
|
my (@configs,@commands,@standard,%checked,%custom,%customargs); |
|
my $count = 0; |
|
my $changes = 0; |
|
if (open(my $locfh,"</home/httpd/lib/perl/loncapa_cron-std")) { |
|
while (<$locfh>) { |
|
my $line = $_; |
|
chomp($line); |
|
$standard[$count] = $line; |
|
if ($line =~ m{^#?\s*\d+[^/]+/}) { |
|
my ($config,$script) = split('/',$line,2); |
|
$script =~ s/\s+$//; |
|
my ($cmd,@args) = split(/\s+/,$script); |
|
$commands[$count] = &escape('/'.$cmd); |
|
$configs[$count] = $config; |
|
} |
|
$standard[$count] = $line; |
|
$count ++; |
|
} |
|
close($locfh); |
|
if (open(my $stdfh,"</etc/cron.d/loncapa")) { |
|
while(<$stdfh>) { |
|
my $line = $_; |
|
chomp($line); |
|
if ($line =~ m{#?\s*\d+[^/]+/}) { |
|
my ($config,$script) = split('/',$line,2); |
|
$script =~ s/\s+$//; |
|
my ($cmd,@args) = split(/\s+/,$script); |
|
my $key = &escape('/'.$cmd); |
|
$custom{$key} = $config; |
|
$customargs{$key} = \@args; |
|
} |
|
} |
|
} |
|
if (open(my $newfh,">/etc/cron.d/loncapa")) { |
|
for (my $i=0; $i<@standard; $i++) { |
|
if ($commands[$i] ne '') { |
|
my $unesc = &unescape($commands[$i]); |
|
if ($custom{$commands[$i]} ne $configs[$i]) { |
|
print $newfh $custom{$commands[$i]}.$unesc; |
|
if (ref($customargs{$commands[$i]}) eq 'ARRAY') { |
|
if (@{$customargs{$commands[$i]}} > 0) { |
|
print $newfh ' '.join(' ',@{$customargs{$commands[$i]}}); |
|
} |
|
} |
|
print $newfh "\n"; |
|
$changes ++; |
|
} else { |
|
print $newfh $standard[$i]."\n"; |
|
} |
|
$checked{$commands[$i]} = 1; |
|
} else { |
|
print $newfh $standard[$i]."\n"; |
|
} |
|
} |
|
foreach my $key (sort(keys(%custom))) { |
|
unless ($checked{$key}) { |
|
my $unesc = &unescape($key); |
|
print $newfh $custom{$key}.$unesc; |
|
if (ref($customargs{$key}) eq 'ARRAY') { |
|
if (@{$customargs{$key}} > 0) { |
|
print $newfh ' '.join(' ',@{$customargs{$key}}); |
|
} |
|
} |
|
print $newfh "\n"; |
|
} |
|
} |
|
close($newfh); |
|
} |
|
} |
|
if ($changes>1) { |
|
print "$changes customized lines preserved in /etc/cron.d/loncapa\n"; |
|
} elsif ($changes==1) { |
|
print "One customized line preserved in /etc/cron.d/loncapa\n"; |
|
} |
|
|
|
sub escape { |
|
my $str=shift; |
|
$str =~ s/(\W)/"%".unpack('H2',$1)/eg; |
|
return $str; |
|
} |
|
|
|
sub unescape { |
|
my $str=shift; |
|
$str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; |
|
return $str; |
|
} |
</perlscript> |
</perlscript> |
</file> |
</file> |
</files> |
</files> |