Solved

/usr/bin/perl wrapper for multiple OS

Posted on 1997-08-29
7
505 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

23 Experts available now in Live!

Get 1:1 Help Now