[LON-CAPA-cvs] cvs: doc /loncapafiles cron_lpmlcheck.piml loncapafiles.lpml

raeburn raeburn@source.lon-capa.org
Sun, 23 May 2010 16:07:09 -0000


raeburn		Sun May 23 16:07:09 2010 EDT

  Modified files:              
    /doc/loncapafiles	loncapafiles.lpml cron_lpmlcheck.piml 
  Log:
  - Allow updates to LON-CAPA cron in /etc/cron.d/loncapa
  - Preserve local customizations in timing/frequency of any standard comands run by cron.
  
  
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.685 doc/loncapafiles/loncapafiles.lpml:1.686
--- doc/loncapafiles/loncapafiles.lpml:1.685	Fri May 21 23:03:13 2010
+++ doc/loncapafiles/loncapafiles.lpml	Sun May 23 16:07:09 2010
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.685 2010/05/21 23:03:13 raeburn Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.686 2010/05/23 16:07:09 raeburn Exp $ -->
 
 <!--
 
@@ -7020,6 +7020,14 @@
   </dependencies>
 </file>
 <file>
+  <source>loncom/cron/loncapa</source>
+  <target dist='default'>home/httpd/lib/perl/loncapa_cron-std</target>
+  <categoryname>handler</categoryname>
+  <description>
+    Back-up of standard loncapa cron file (the actual file in use: /etc/cron.d/loncapa may contain local modifications).
+  </description>
+</file>
+<file>
 <source>loncom/ntp/step-tickers</source>
 <target dist='default'>usr/local/loncapa/doc/conf_examples/ntp_step-tickers
 </target>
Index: doc/loncapafiles/cron_lpmlcheck.piml
diff -u doc/loncapafiles/cron_lpmlcheck.piml:1.1 doc/loncapafiles/cron_lpmlcheck.piml:1.2
--- doc/loncapafiles/cron_lpmlcheck.piml:1.1	Wed Jun 23 14:41:38 2004
+++ doc/loncapafiles/cron_lpmlcheck.piml	Sun May 23 16:07:09 2010
@@ -3,7 +3,7 @@
 <!-- cron_lpmlcheck.piml -->
 <!-- Matthew Hall -->
 
-<!-- $Id: cron_lpmlcheck.piml,v 1.1 2004/06/23 14:41:38 matthew Exp $ -->
+<!-- $Id: cron_lpmlcheck.piml,v 1.2 2010/05/23 16:07:09 raeburn Exp $ -->
 
 <!--
 
@@ -38,6 +38,93 @@
 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,"&lt;/home/httpd/lib/perl/loncapa_cron-std")) {
+    while (&lt;$locfh&gt;) {
+        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,"&lt;/etc/cron.d/loncapa")) {
+        while(&lt;$stdfh&gt;) {
+            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,"&gt;/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&gt;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>