/usr/bin/perl wrapper for multiple OS

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
hiattAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ahoffmannConnect With a Mentor Commented:
your wrapper must call perl with the -S option, like:
  exec ${PERL} -S path_to_you_perl_script ${1+"$@"}
0
 
n0thingCommented:
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
 
hiattAuthor Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ozoCommented:
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
 
hiattAuthor Commented:
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
 
ahoffmannCommented:
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
 
hiattAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.