Hi Monks,
I am changing/adding lines in bunch of files.
if $line is something. Change it to something else.
elsif $line is correct. leave it alone with next.
elsif $line isn't there. Put, it there.
If works,
elsif removes the $line if the $line is there.
elsif the line isn't there. Add it.
That works. But,the if/elsif/ also add there stuff too.
Then if I put else {next}; That Totally screws up the out file.
Can you tell me what is wrong?
Thanks!
#!/usr/bin/perl -w
use strict;
my $agent = "best1agent_start";
my $bgs=<<HERE;
'bgs')
/usr/bin/su - patrol /usr/adm/best1_default/bgs/scripts/best1collect
+ -q>>\$LOG 2>>\$LOG
;;
HERE
my $collect = " /usr/bin/su - patrol /usr/adm/best1_default/bgs/scr
+ipts/best1collect -q>>\$LOG 2>>\$LOG\n";
my $cf_dir = "/export/home/f358118/sysedge";
open SH_FILES, "sys.sh" or die "Error: $!";
my @sh_f=<SH_FILES>;
close SH_FILES;
foreach my $sh(@sh_f){
chomp $sh;
open(OUT, ">/$cf_dir/$sh".".OUT")or die "ERROR $!";
my $line;
open (SH, "$cf_dir/$sh") or die "ERROR $!";
while ($line = <SH>){
if($line =~ m/$agent/){
$line = $collect;
} elsif ( $line =~ m/best1collect/) {
next;
} elsif ($line =~ m/'syslogd'\)/){
my $newline = $. + 3;
$newline = $bgs;
print OUT "$newline\n";
}
#else { next };
print OUT $line;
print $line;
}
}