Solved

/usr/bin/perl wrapper for multiple OS

Posted on 1997-08-29
7
506 Views
Last Modified: 2008-02-26
Hi,

 I wrote a really brain damaged wrapper(see below) to select between
the sunOS or solaris perl binary. This works fine when invoked from
the command line, however, for scripts that actually invoke the
wrapper (ie, #!/bin/perl) it fails horrible. In fact, it tries to
execute the script without invoking perl.

 Could someone give me a clue as to what I am doing wrong (besides using
/bin/sh). :)

 Thank you,

don
 


---- snip (/bin/perl) ---

#!/bin/sh
sunPERL="/usr/test/perl/sparc-sun-sunos4.1.3/bin/perl"
solarisPERL="/usr/test/perl/sparc-sun-solaris2.5/bin/perl"
PERL=${sunPERL} # default

if [ -f /bin/uname ] ; then  # Make sure we have uname
        VERSION=`/bin/uname -r`
        #echo "OS VERSION: ${VERSION}"
        if [ $VERSION -gt 4 ] ; then  # Solaris
                PERL=${solarisPERL}
        else                          # SunOS
                PERL=${sunPERL}
        fi
else
        echo "Error: Can not find uname"
        exit 1
fi

exec ${PERL} ${1+"$@"}

exit 1

--
"Don Hiatt" <hiatt@cig.mot.com>
Key fingerprint =  72 83 9B 82 FF DB F5 97  53 78 01 00 22 4C 95 A0
0
Comment
Question by:hiatt
7 Comments
 
LVL 5

Expert Comment

by:n0thing
ID: 1205842
Hi,

   I'm not sure where the problem is. But I've a simple solution
to your problem by using symlink.

----- Your perl script -----
#!/usr/myperl
perl code ....

-----

---- Your shell script ----
#!/bin/sh
....
if solaris ...
   ln -fs /usr/bin/solaris/perl /usr/myperl
else ln -fs /usr/bin/sunos/perl /usr/myperl
fi
/usr/home/my/perl/script
--------------------------------------------
By using this strategy .. you will only be creating a symbolic link to the actual perl binary of your choice. So your scripts will use the same path and you don't have to "exec perl ..."
in your shell script which is causing the problem.

Regards,
Minh Lai


0
 

Author Comment

by:hiatt
ID: 1205843
Minh Lai,

 I know I can do something like this. The problem is that I would have to modify *a lot* of scripts which are spread out across *many* hosts. So, this really isn't possible. What I need is a a way to have each script (with #!/bin/perl) invoke /bin/perl which is actually a wrapper which determines your arch/os (dec, next, sun, solaris, aix, sgi, etc) and then invoke the "real" pearl (ie, pearl binary for that architecture/os).

  Thank you very much for your suggestion!

don

0
 
LVL 84

Expert Comment

by:ozo
ID: 1205844
This seems to be more of a Unix problem than a Perl problem
I don't think you can (portably) #!pathname to another #!pathname
Couldn't you make /bin/perl a link on each local host
pointing to the appropriate binary for that host?
(after all you're depending on /bin/sh and /bin/uname to point
to the binary appropriate to each host)
 

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 1205845
your wrapper must call perl with the -S option, like:
  exec ${PERL} -S path_to_you_perl_script ${1+"$@"}
0
 

Author Comment

by:hiatt
ID: 1205846
This won't work either. It seems it is not possible using a #!
script. Have a look at this:

http://xp10.dejanews.com/getdoc.xp?recnum=5434053&search=thread&threaded=1&server=db95q4&CONTEXT=873305307.962267844&HIT_CONTEXT=873304654.1167722027&HIT_NUM=27&hitnum=3&NTL=1

Thank you for your help,

don

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1205847
I've read the article you mentioned.
I think it doesn't match our perl problem.
Reason:
  exec, in fact, starts an interpreter, but this one (perl) does
  not depend on the #! (nevertheless, AFAIK perl checks this line
  for its own options)
This would be true if the started program (by exec) is an script to be interpreted by a shell itself. But we start an an other program, perl.
0
 

Author Comment

by:hiatt
ID: 1205848
Yes, but the problem is that I have some script called "foo".
And "foo" starts like this: "#!/usr/bin/perl". Also note, that
"foo" requires arguments from the user. Now, "/usr/bin/perl" is
a shell script that exec the real perl. I have tried the "-S.."
options, and what happens is that the script, "foo", is executed
without the perl interpreter. Example,
      
      Say, "foo" looks like this

      #!/usr/test/bin/perl
      print "hi";
      exit;

         When I execute the wrapper, I get

            print: Command not found.


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connecting to linux server using Net::Telnet module 25 220
perl split by | 2 90
Perl passing in variables to do substitution 6 66
How to generate square thumbnail using perl 13 77
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now