Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

perl script quesion pls

Posted on 2004-11-02
2
Medium Priority
?
305 Views
Last Modified: 2008-02-01
hi all,

i don't know anything about perl but since peer who wrote perl has left, I have to learn this as well accomplish this.. may be it is simple change, which you experts can help me in a min.

here is the issue..

there is perl script (on SOLARIS 5.8) which is called fixPrototype.pl which actually takes an argument as name of file (which is always "prototype) and fixes some stuff in this file..

so we will call

fixprototype.pl prototype

and it will change prototype file by fixing few things..

prototype file looks as below (only few lines)..

#ident  "%W%"
i       pkginfo
i       copyright
i       request

x none $OPTDIR 0755 $OWNER $GROUP

!search $INSDIR
f none $OPTDIR/docs.jar 0644 $OWNER $GROUP
x none $OPTDIR/appvar 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/CIO 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/FRANKRUSSELL 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/GENERIC 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/JPMORGAN 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/LJR 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/MELLON 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/MERCER 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/NORTHERNTRUST 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/P2P 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/PF 0755 $OWNER $GROUP
x none $OPTDIR/data 0755 $OWNER $GROUP
x none $OPTDIR/data/AUS 0755 $OWNER $GROUP
x none $OPTDIR/data/CMTA 0755 $OWNER $GROUP
x none $OPTDIR/data/GMRS 0755 $OWNER $GROUP
x none $OPTDIR/data/LEBL 0755 $OWNER $GROUP
x none $OPTDIR/data/RETAIL 0755 $OWNER $GROUP
x none $OPTDIR/data/logs 0755 $OWNER $GROUP
x none $OPTDIR/data/logs/app 0755 $OWNER $GROUP
x none $OPTDIR/data/logs/appsrv 0755 $OWNER $GROUP
x none $OPTDIR/data/logs/autosys 0755 $OWNER $GROUP
x none $OPTDIR/docs 0755 $OWNER $GROUP

and fixPrototype.pl looks as below (complete code)


#!/opt/perl/5.8.0/bin/perl
#ident      "%W%"
#==================================================
# GLOBAL VARIABLES
#==================================================

$filename      = $ARGV[0];
$myOwner      = $ARGV[1];
$myGroup      = $ARGV[2];
if ($myOwner eq '-' || $myOwner eq "" ) { $myOwner = '$OWNER'; }
if ($myGroup eq '-' || $myGroup eq "" ) { $myGroup = '$GROUP'; }

$wfilename      = $filename.$$;

#print "OWNER = $myOwner\n";

#==================================================
# USUAGE
#==================================================
sub helpme {

      print "\nUSAGE : \n";
      print "$0 <file name> <owner> <group>";
      print "\nex: $0 prototype isoft wls61";
      print "\n if <owner> and/or <group> is a dash (-) then it will default to \$OWNER \and/or $GROUP resp. from request script";
      print "\n\n";
      exit;
}

#==================================================
# PROGRAM
#==================================================

sub changeLine {
      my ($line, $perm, $owner, $group) = @_;
      $line =~ s/\$OWNER/$owner/;
      $line =~ s/\$GROUP/$group/;
      if ( $line =~ m#\s(\d\d\d\d)\s# ) {
            $line =~ s/$1/$perm/;
      }

      return $line;
}

if ( $ARGV[0] =~ /help/i || (length(@ARGV)+1) != 2 ) {
      &helpme;
} elsif (! -f $filename) {
      print "ERROR: $filename NOT found!\n";
      exit;
}

open(READPERL, "<$filename") || die "CANNOT OPEN $filename for reading";
open(WRITEPERL, ">$wfilename") || die "CANNOT OPEN $wfilename for writing";

while (my $line = <READPERL>) {

            if ($line =~ m|\$OPTDIR/data |) {
                  # if we leave this line in prototype,
                  # sym link will be removed and a physical directory will
                  # be created instead - bad.
                  # by removing it the other dirs spcified in protoype under data will still get created
                  # but they will get created on ftp nfs server as we want
                  
                  # touch this line and die!!!! - ask Scot B first

            } elsif ($line =~ m|\$OPTDIR/weblogic/etc|) {
                  # for shell scripts, etc.
                  print WRITEPERL changeLine($line, '0775', '$OWNER', '$GROUP');
            } elsif ($line =~ m|\$OPTDIR/appvar/upload |) {
                  # general location for writing files by weblogic
                  print WRITEPERL changeLine($line, '0775', 'wls61', '$GROUP');
            } elsif ($line =~ m|\$OPTDIR/appvar/upload/|) {
                  # general location for writing files by weblogic
                  print WRITEPERL changeLine($line, '0775', 'wls61', 'isoft');
              } elsif ($line =~ m|\$OPTDIR/logs/autosys|) {
                  # general location for writing autosys logs
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
              } elsif ($line =~ m|\$OPTDIR/logs|) {
                  # general location for writing logs
                  print WRITEPERL changeLine($line, '0775', 'wls61', '$GROUP');
            } elsif ($line =~ m|\$OPTDIR/data/|) {
                  # general location for data files
                  # make it writable by isoft and wls61
                  # isoft - as this is the id autosys runs as
                  # wls61 as this is the id weblogic runs as
                  print WRITEPERL changeLine($line, '0775', 'wls61', 'isoft');
            } elsif ($line =~ m|config.xml|) {
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
            } elsif ($line =~ m|setEnv.sh|) {
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
            } elsif ($line =~ m|50006_AutosysProfile.sh|) {
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
            } elsif ($line =~ m|rits_ldap.properties|) {
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
            } else {
                  printf WRITEPERL $line;
            }
}

rename($wfilename, $filename);
close(READPERL);
close(WRITEPERL);



Bascially Requirement is as below:

I have to enhance pl script so that before fixing anything, it should read the prototype file and when it finds the line
i       request


after that it should insert a new line saying

i<tab>postinstall

so bascially new prototype file (only few lines) should look as below


#ident  "%W%"
i       pkginfo
i       copyright
i       request
i       postinstall

x none $OPTDIR 0755 $OWNER $GROUP

!search $INSDIR
f none $OPTDIR/docs.jar 0644 $OWNER $GROUP
x none $OPTDIR/appvar 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload 0755 $OWNER $GROUP

and the fixes which perl script is already doing..


hope you can help me with this...

regards
0
Comment
Question by:shivani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 500 total points
ID: 12473209
add another elsif:

    elsif( $line =~ m|^i\trequest| ) {
        # add postinstall line
        print WRITEPERL $line . "i\tpostinstall\n";
    }
0
 
LVL 13

Expert Comment

by:gripe
ID: 12473210
> I have to enhance pl script so that before fixing anything

Why do you have this requirement? If you see the line 'i     request' do you want to stop processing and ONLY change that line or do you want to continue on with the normal changes on the script. If you want to continue on, this is a simple matter of adding another elsif clause to your if/else statement, like so:

          } elsif ($line =~ m|i\trequest|) {                  # match i followed by a tab followed by request
               print WRITEPERL "$line\ni\tpostinstall\n"; # print the i<tab>request line followed by a i<tab>postinstall line
          }

Hope this helps.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question