cadphile has asked for the wisdom of the Perl Monks concerning the following question:
We have a huge number of installed scripts, that all are written with #!/<perlpath>/bin/perl in line 1 of the scripts (we're in a Solaris environment, and have had an exclusive Sparc compute environment). We've recently added gobs of i386/Solaris servers in our server room, and I want to be able to have users run all these hundreds of scripts on the i386, or sparc platforms, without having to change all the scripts, and/or make separate i386 versions that point to a separate i386 perl build.
So, I've built the sparc, and the i386 versions *together*, and installed the binaries separately using --installbin=<perlpath>/i386/bin (for i386) and --installbin=<perlpath>/sparc/bin for sparc. Then in the directory "<perlpath>/bin", I made the file "perl" into a shell script, to figure out what machinetype the user is on, then exec to the ../i386/bin/perl, or ../sparc/bin/perl, respectively. So my single installation, has a separate architecture area for sun4-solaris-64int, and another for i86pc-solaris-64int. The non-architecture-dependent modules are all shared, and there are separate bin dirs for the perl binaries. The "perl-5.8.8/bin" directory then is just filled with wrappers that resolve the correct build bin...
So, this works fine, if the tool/script is written as follows:
because the unix kernel is just doing a sh exec to the <perlpath>/bin/perl file, which is my bourne shell wrapper. No problem. The problem is that all the tools/scripts use the form:#!/bin/sh -- # -*- perl -*- eval 'exec <perlpath>/bin/perl -S $0 ${1+"$@"}' if 0;
and in this case, the unix kernel is looking at <perlpath>/bin/perl, and noting that this is not a binary file, and that it doesn't return the appropriate "magic number", and so decides, that this file is not execl()-able. Therefore, it wrongly decides that it's a csh script (because it's char#1,col#1 character is "#"), and therefore begins parsing the script as a csh script, and quite quickly royally croaks....#!<perlpath>/bin/perl
OK, so (finally my question!) how can I trick the kernel into executing the target interpreter path of a perl script that begins with #!<perlpath>/bin/perl, when <perlpath>/bin/perl is a bourne shell wrapper? Here's the wrapper script, if you're interested:
#!/bin/sh ## this is the wrapper file: <toolroot>/perl-5.8.8/bin/perl die () { echo "ERROR: $1"; exit 1; } tool=`/usr/bin/basename $0` perlroot=<mytoolroot>/tools/perl-5.8.8 arch=`/usr/bin/mach`; ## try to exec the perl binary exe=$perlroot/$arch/bin/$tool if [ -x $exe ]; then eval 'exec $exe ${1+"$@"}' else die "Couldn't find $tool executable: \"$exe\"."; fi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using "#!/<perlpath>/bin/perl" to exec a shell script?
by graff (Chancellor) on Oct 04, 2007 at 02:48 UTC | |
by cadphile (Beadle) on Oct 04, 2007 at 04:14 UTC | |
by graff (Chancellor) on Oct 04, 2007 at 04:57 UTC | |
|
Re: using "#!/<perlpath>/bin/perl" to exec a shell script?
by roboticus (Chancellor) on Oct 04, 2007 at 02:15 UTC | |
by cadphile (Beadle) on Oct 04, 2007 at 03:23 UTC | |
|
Re: using "#!/<perlpath>/bin/perl" to exec a shell script?
by perlfan (Parson) on Oct 04, 2007 at 03:59 UTC | |
by cadphile (Beadle) on Oct 04, 2007 at 04:43 UTC | |
by russoz (Initiate) on May 07, 2008 at 03:15 UTC |