-1

I have a perl job migrated from a Solaris server to a Linux server that is failing I believe because the Linux version is not respecting the shebang, which the Solaris server handled no problem.

perl file shebang:

#!/apps/sun5/.../software/perl/bin/perl

Solaris version:

SunOS 5.10 Generic_150400-63 sun4u sparc SUNW,Sun-Fire-V445

Linux version:

Linux 2.6.32-754.23.1.el6.x86_64 

To get the job to complete successfully, I've had to revert to the old Solaris server. Is there a tweak I can make to the shebang so that the script is recognized as a perl script by the Linux server?

Conner M.
  • 1,954
  • 3
  • 19
  • 29
  • 2
    Does you Linux server have the `/apps/sun5` directory? – mob Dec 05 '19 at 22:00
  • (Linux limits the shebang to around 128 characters too... not sure how long your actual path it) – Sean Bright Dec 05 '19 at 22:01
  • @mob yes, the shebang dir is on the Linux server – Conner M. Dec 05 '19 at 22:02
  • That seems highly unlikely, a Linux Perl would not be installed in such a place. If you copied the Perl from the Solaris server, it will not work because it is a different architecture. – Grinnz Dec 05 '19 at 22:04
  • Judging by the timestamp for the /bin/perl file on the Linux server, i.e. Nov 10 2010, it may have just been synced over. Same timestamp on the Solaris server. – Conner M. Dec 05 '19 at 22:13
  • You need to use a Perl that was build for that Linux architecture. There will probably be one at `/usr/bin/perl` but depending on Linux distribution you may need to install additional packages for it to be complete, and it's best to keep applications separate from the Perl used by the system. You can use [perl-build](http://metacpan.org/pod/perl-build) to build any specific version of Perl on the Linux machine in an arbitrary location. Even though Perl tries to remain compatible across versions, you should start by building the same version of Perl as it was running with on Solaris. – Grinnz Dec 05 '19 at 23:34
  • Did you try to run `which perl`? Did you try to run `perl` manually to see if it will respond to the call? – Polar Bear Dec 06 '19 at 02:34
  • Change your shebang to `/usr/bin/env perl`. On Solaris, put `/apps/sun5/.../software/perl/bin` on-path, before the other `bin/` folders like `/usr/bin` and `/usr/ucb/bin`. Also see [Why is #!/usr/bin/env bash superior to #!/bin/bash?](https://stackoverflow.com/q/21612980/608639), [Why is it better to use “#!/usr/bin/env NAME” instead of “#!/path/to/NAME” as my shebang?](https://unix.stackexchange.com/q/29608), [Make Linux/Unix Script Portable With #!/usr/bin/env As a Shebang](https://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html), etc. – jww Dec 06 '19 at 03:29
  • Dear, these are really the basics, get some training. The file command is also your friend, it will tell you for what cpu type the binary has been compiled and linked. And if a folder is named sun5 .. well then expect binaries there for a sun5 HW architecture. Your Linux is must likely based on Intel or AMD CPU. Then you need to look where the perl binaries of your system are. Enter "which perl" on the command line in the hope your PATH variable is properly set. Otherwise use "find / -type f -name perl -print" and think about which path makes sense ... – ennox Dec 06 '19 at 13:44

1 Answers1

1

Change your shebang line to #!/usr/bin/perl or wherever perl is installed. Another alternative is #!/bin/env perl if perl is in your PATH.

ysth
  • 96,171
  • 6
  • 121
  • 214
Tanktalus
  • 21,664
  • 5
  • 41
  • 68
  • Did you see @Grinnz comment? The perl is installed at the shebang location. But it sounds like it might not be compatible with the Linux architecture. Do you know if there are different perl versions for Linux vs Solaris? – Conner M. Dec 05 '19 at 22:39
  • 2
    The perl installed at that location is a solaris binary, not compatible with the linux kernel. It won't run. Use the Linux version of perl that's installed with Linux. Custom perl installations across platforms (OS/CPU) can be done, but are generally much more complex than is required. – Tanktalus Dec 05 '19 at 22:49
  • @Conner M., What are you trying to do? If you're doing this because you want a specific version of Perl, that's pretty easy to do (and especially so using `perlbrew`). – ikegami Dec 06 '19 at 03:57