File:
[LON-CAPA] /
doc /
loncapafiles /
cron_lpmlcheck.piml
Revision
1.3:
download - view:
text,
annotated -
select for diffs
Fri Jun 25 16:39:01 2010 UTC (14 years, 5 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_1,
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
HEAD,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- Prevent removal of configuration items before the script path in new entries in loncapa
cron.
<!DOCTYPE piml PUBLIC "-//TUX/DTD piml 1.0 Final//EN"
"http://lpml.sourceforge.net/DTD/piml.dtd">
<!-- cron_lpmlcheck.piml -->
<!-- Matthew Hall -->
<!-- $Id: cron_lpmlcheck.piml,v 1.3 2010/06/25 16:39:01 raeburn Exp $ -->
<!--
This file is part of the LearningOnline Network with CAPA (LON-CAPA).
LON-CAPA is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LON-CAPA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LON-CAPA; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/home/httpd/html/adm/gpl.txt
http://www.lon-capa.org/
-->
<piml>
<targetroot>/</targetroot>
<files>
<file>
<target dist="default">/home/httpd/lonUsers</target>
<perlscript mode="fg">
if (-e '/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]} eq '') {
print $newfh $standard[$i]."\n";
} elsif ($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>
</file>
</files>
</piml>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>