#!/usr/bin/perl my @abqcrap; print "What file will we use for the new values?\n"; chomp($nvars = ); print "Is this the prod user or the dev user?\n"; chomp($user = ); if ( $user eq "prod" ) { $oldenv="abqenv"; $newenv="sysenv"; $olduser="abqapps"; $newuser="sysapps"; $oldsid="apabq"; $newsid="apsys"; } else { $oldenv="devaenv"; $newenv="devsenv"; $olduser="devaapps"; $newuser="devsapps"; $oldsid="apabqd"; $newsid="apsysd"; } # print "olduser = $olduser\n"; sub domojo2 { $abqsids="@abqsids"; @search = ($olduser, $oldsid, $oldenv); @replace = ($newuser, $newsid, $newenv); foreach (0..$#search) { $abqsids =~ s/$search[$_]/$replace[$_]/g; } push (@newfile, $abqsids); # Since this line is in the file twice, we need to clear out these variables or we end # up with the line repeated undef $abqsids; undef @abqsids; } sub domojo { $abqenv = "@abqenv"; # convert it to a string, so we can split it @abqenv2 = split(/;/, $abqenv); # take the ";" out of each line for ($i=0;$i<=$#abqenv2;$i=$i+2) { # We need to increment by 2, not by 1; push (@varpairs, $abqenv2[$i]); #@argh="EXEPATH=${PATHPROD}/${BINCOAD} LOGPATH=${PRODLOG}/CO/adage AP_USERNAME=M2/M2_DBA@abqp WHSE=003" push (@exports, $abqenv2[$i+1]); # All the "export XXX" lines. need for putting it back together later } while (<@varpairs>) { @varpairs = split(/=/); # Take out teh "=" push (@varsonly, $varpairs[0]); # Only the variable names push (@valuesonly, $varpairs[1]); # Only the values of the variables } for ($i=0;$i<=$#varsonly;$i++) { # Give them the value that is in the environment vars file print "Whats the new value for $varsonly[$i] : ($User_Preferences{$varsonly[$i]})\n"; chomp ($answ = ); if ($answ eq "") { # If they just hit 'return', the new value will be what the value from the environemtn vars file is. $answ = $User_Preferences{$varsonly[$i]}; } print "answ = $answ\n"; push (@newvalueonly, $answ); } push (@newloc, "$newenv () {\n"); for ($i=0;$i<=$#varsonly;$i++) { $string = " @varsonly[$i]=@newvalueonly[$i]; @exports[$i];\n"; push (@newloc, $string); undef $string; } push (@newloc, "}\n\n"); } $todo=@ARGV[0]; open ( FILE, "notdone/$todo" ) or die "cannot open $file: $!"; $foundAbq=0; # Read in the new environment vars from a file open ( CONFIG, "$nvars" ) or die "cannot open $file: $!"; while () { chomp; # no newline s/#.*//; # no comments s/^\s+//; # no leading white s/\s+$//; # no trailing white next unless length; # anything left? my ($var, $value) = split(/\s*=\s*/, $_, 2); #my ($var, $value) = split(/=/, $_, 2); $User_Preferences{$var} = $value; } while () { #push (@newfile, $_); $prevabqcount = 0; $lastWasAbq=$foundAbq; if ( /^$oldenv/ .. /^}/ ) { # we want the whole abqenv bit next if /^(\s)*$/; # skip empty lines next if /^$oldenv \(\)*(.*){$/; # skip 'abqenv () {' lines next if /^$oldenv\(\)*(.*){$/; # skip abqenv() {' lines next if /(.*)#/; # skip commented lines next if /^}/; # skip where '}' is the first char on a line push (@abqenv,$_); # put it all in teh @abqcrap array #$abqcount = @abqcrap; $foundAbq=1; } else { $foundAbq=0; } if(($lastWasAbq == 1) && ($foundAbq == 0)) { domojo; $lastWasAbq = 0; push (@newfile, @newloc); } $prevabqcount2 = 0; $lastWasAbq2=$foundAbq2; if ( /^\s*$olduser/ .. /^\s*$oldenv\;\;/ ) { # we want the whole abqenv bit next if /^(\s)*$/; # skip empty lines next if /(.*)#/; # skip commented lines push (@abqsids,$_); # put it all in teh @abqsids array #$abqcount = @abqcrap; #print "abqcrap = @abqcrap\n"; $foundAbq2=1; } else { $foundAbq2=0; } if(($lastWasAbq2 == 1) && ($foundAbq2 == 0)) { domojo2; # this does the s/r for abqapps) portion #print "abqcrap2=@abqcrap\n"; $lastWasAbq2 = 0; } push (@newfile, $_); } # print @newfile; #} open ( NEWFILE, ">notdone/$todo-new" ) or die "cannot open $file: $!"; print NEWFILE @newfile;