I have a bunch of files. Some have the line change. Some do not and it needs to be added. Some have the the line, but it is wrong. So, I need to change it.
I've tried it several different ways.
Any thoughts would be appreciated.
I would like each file to have:
'bgs')
/sbin/sh /usr/adm/best1_default/bgs/scripts/best1agent_start >>\$LOG
+ 2>>\$LOG
;;
It is kind of a mess now.
Thanks!
#!/usr/bin/perl -w
use strict;
my $CF_bgs = "watch process procAlive 'bgs' 8 0x2 60 'Productio
+n Critical: bgs failure. Restarting bgs''/opt/EMPsysedge/bin/sysedge
+.sh'";
my $bgs=<<HERE;
'bgs')
/sbin/sh /usr/adm/best1_default/bgs/scripts/best1agent_start >>\$LOG
+ 2>>\$LOG
;;
HERE
#my $BestAgent = "/sbin/sh /usr/adm/best1_default/bgs/scripts/best1age
+nt_start>>\$LOG 2>>\$LOG";
#my $BestCollect = "/usr/bin/su - patrol /usr/adm/best1_default/bgs/sc
+ripts/best1collect -q>>\$LOG 2>>\$LOG";
open CF_FILES, "cf.files" or die "$!";
open SH_FILES, "sh.files" or die "$!";
my @cf_files=<CF_FILES>;
my @sh_files=<SH_FILES>;
close CF_FILES;
close SH_FILES;
my @CF_L = grep(/bgs/, @cf_files);
foreach my $cf(@cf_files){
chomp $cf;
my $cf_temp = "$cf".".sysedge";
open F, "$cf";
my @F_cf = <F>;
# my @CF_L = grep("bgs", @F_cf);
open(TMP, ">/tmp/$cf_temp");
my $line;
while($line = <F>){
if($line =~ m#'bgs'#){
print $line;
$line = "$CF_bgs\n";
#my $newline = $. + 1;
print $line;
} elsif ( $line =~ m#'syslogd'# ){
my $newline = $. + 1;
$newline = $CF_bgs;
print TMP "$newline\n";
}
print TMP $line;
}
close TMP;
close F;
}
#print @CF_L;
#print @cf_files;
#rename("out.$test", $test);