/ /home/httpd/lonUsers 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; }