From 4e953583a7a185e6285eafaa4dd02dd3c35359b0 Mon Sep 17 00:00:00 2001 From: Mikael Nordin Date: Mon, 16 Jan 2017 14:41:21 +0100 Subject: [PATCH] working uncomment --- cluster_cron.pl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cluster_cron.pl b/cluster_cron.pl index dacfa62..e63714e 100755 --- a/cluster_cron.pl +++ b/cluster_cron.pl @@ -154,7 +154,7 @@ sub uncomment { open(INFILE,"<$infile"); my $content = ''; while(my $line = ) { - $line =~ s/^(#\s?)([\d*])/ $2/g; + $line =~ s/^#\s{1,4}([\d\*])/ $1/g; $content .= $line; } @@ -216,9 +216,18 @@ sub run { # If we have an active shared cronfile, we should also have an old shared # See if I am the one if (is_active(get_nodes) ){ - if(compare($cronfile, $passivesharedcronfile) == 0 and compare($cronfile, $activesharedcronfile) != 0) { - print "There has been a failover, switching to active cronfile\n"; - copy($activesharedcronfile, $cronfile); + if(compare($cronfile, $passivesharedcronfile) == 0 ) { + my $is_empty = 1; + open my $fh, '<:encoding(UTF-8)', $activesharedcronfile or die; + while (my $line = <$fh>) { + if ($line !~ m/^#/) { + $is_empty = 0; + } + } + unless($is_empty) { + print "There has been a failover, switching to active cronfile\n"; + copy($activesharedcronfile, $cronfile); + } } my $tempfile = tmpnam(); my $compare = cron_compare($cronfile, $activesharedcronfile, $oldactivesharedcronfile );