Ovid has asked for the wisdom of the Perl Monks concerning the following question:

I'm a relatively new to Linux, so I'm in over my head here. I'm having a problem with a shebang line and multiple versions of Perl.

One of our scripts runs fine from the command line but wouldn't run through the browser. We'd type

perl somescript.cgi

and everthing would run fine.

However, when we tried

./somescript.cgi

we would get a "No such file or directory" error. The shebang line was #!/usr/bin/perl and sure enough, there is a /usr/bin/perl out there.

After copying a shebang from another script, we discovered that it would run perfectly by enabling warnings (wtf???). Shebang:

#!/usr/bin/perl -wT

Take out the -w and the script won't run. /usr/bin/perl has perl 5.6.0. We discovered that we also have a /usr/local/bin/perl which is version 5.6.1 (which could be a red herring). I'm trying to figure out if there is some version conflict going on here, though I don't see how.

Anyone run across a problem like this before? We're running RedHat Linux version 7.0. Perl 5.6.1 was installed after the RedHat install.

Cheers,
Ovid

Vote for paco!

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: Turning *off* warnings causes the script to fail :(
by blakem (Monsignor) on Aug 21, 2001 at 02:16 UTC
    I ran into something similiar, once... Have you checked to see if your end-of-line character is incorrectly set to '\r\n'? If your script starts with

    #!/usr/bin/perl\r\n

    it will be looking for a file called 'perl\r' in /usr/bin. Whereas

    #!/usr/bin/perl -wT\r\n
    Will actually work.

    Do a quick 'hexdump -c filename' to see if this is the case.

    Update: A bit more about the time I got bit by this.... I had a jr sysadmin working under me put a new 'ifcfg-eth0' to a soon-to-be-production machine with a buch of '\r's in it. It looked something like:

    DEVICE=eth0\r IPADDR=xx.xx.194.149\r NETWORK=xx.xx.194.128\r NETMASK=255.255.255.128\r BROADCAST=xx.xx.194.255\r

    When we cycled the machine right before deploying it, we lost remote connectivity (it was trying to configure the device 'eth0\r'. We had to go down to the colocation facility and debug if from there. The error message on the screen was 'eth0 no such device' (i.e 'eth0\r no such device') which wasn't particularly helpful. After cycling the machine numerous times and swapping out some hardware, someone noticed that emacs was labeling it as a DOS file. A quick 'perl -pi -e "s/\r//g" ifcfg-eth0' fixed it.

    -Blake

      #!/usr/bin/perl -wT\r\n Will actually work.
      That's my guess. I just verified (on Linux and FreeBSD) that a \r won't screw up the #! line if it appears after a command line option. I assume the kernel stops scanning for the path to the executable as soon as it hits whitespace, and that the presense of command-line options are sufficient to prevent the \r from being considered as part of the path of the executable.

      'perl -pi -e "s/\r//g" ifcfg-eth0'
      For the life of me, I could never remember the command-line syntax-ish way of doing things like that. I thank you Blake, you just made my job of moving my mod_perl stuffs around. I'll go about figuring out what -pi -e means, but for now.. it works. :)

      _14k4 - perlmonks@poorheart.com (www.poorheart.com)
Re: Turning *off* warnings causes the script to fail :(
by converter (Priest) on Aug 21, 2001 at 05:33 UTC

    Your shell was trying to run an interpreter called "perl\r". If you want a quickie demo, create a symlink in the directory where the script resides with the following command:

    ln -s `which perl` `echo -ne "perl\r"`

    Now change the shebang line to invoke perl via the symlink in the current directory, being careful not to remove the carriage return:

    #!./perl

    Invoke your script and the shell will exec perl via the "perl\r" symlink without complaint.

    Update: I should add the magic incantation to remove the nasty symlink:

    rm `echo -ne "perl\r"`
Re: Turning *off* warnings causes the script to fail :(
by maverick (Curate) on Aug 21, 2001 at 05:30 UTC
    you could also run the command

    which perl

    to see which the full path to the perl binary for 'perl somescript.cgi'

    try running the script through 'od -c somescript.cgi'. od is essentially a hex dumper, and you should be able to spot if there is anything funky on the shebang line.

    /\/\averick
    perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

Re: Turning *off* warnings causes the script to fail :(
by Anonymous Monk on Aug 21, 2001 at 04:45 UTC
    Another quick thing to check is the path of the perl executable in you PATH variable. Try running from the command line with the full path of perl

     /usr/local/bin/perl somescript.pl

    and see if it fails with the same error message. If it does then likely you have the path for that version in your PATH first and need to put /usr/bin first.
Re: Turning *off* warnings causes the script to fail :(
by Trimbach (Curate) on Aug 21, 2001 at 15:37 UTC
    Strange but no one's mentioned trying to resolve the potential source of the problem itself. I've recently installed RedHat 7.1 on a machine, and also inadvertantly installed 2 versions of Perl (5.6 and 5.6.1). I, too, had the same "it works from the command-line it bombs from the webserver" problem. I fixed everything by going to /usr/bin and then doing a "./perl -MCPAN -e shell" to upgrade the 5.6 (in /usr/bin) which also had the affect of overwritting the 5.6.1 in /usr/local/bin. Once I was down to one version of Perl everything worked as expected. No weirdness. Unless you have a desperate need for two versions of Perl you might give that a try and see if it helps.

    Gary Blackburn
    Trained Killer

      That has nothing to do with the problem.

      The problem here is, "It works when explicitly invoked with perl, but fails when launched as an executable." The reason in this case appears to be a DOS line ending causing a carriage return to be seen as part of the interpreter's name.

        We don't know that for sure just yet... it *could be* a DOS line ending problem, but it *could be* a multiple perl version issue. We still haven't heard back from Ovid on whether any of the suggestions mentioned solves the problem.

        Basically, he needs to use "od -c somescript.cgi" to see if the first line shows a \r on the first line of the script, and he needs to try running from the command line both "/usr/bin/perl somescript.cgi" and "/usr/local/bin/perl somescript.cgi" to make sure they both produce the same results.

        In any the case, lets not get jumpy about it. All the suggestions so far are good ones.

        Zucan

(Ovid as AnonymousM) Re: Turning *off* warnings causes the script to fail :(
by Anonymous Monk on Aug 21, 2001 at 19:13 UTC

    This is Ovid posting as He Who Must Not Be Named. No need to XP whore for a 'thanks'.

    blakem wins the non-existent prize for fastest answer (he even beat some of the mailing lists I'm on).

    We've tracked down what happened. Seems that some sent a zipped file to our server via FTP instead of just sending the plain text file. By extracting the file directly on the Linux box, the DOS line endings were preserved (most FTP clients can convert them for you).

    Yet another piece of information for my clue box :)

      Cool, glad to know that it helped... Something just clicked at "I'm relatively new to Linux" on my second reading. It reminded me of the 'eth0\r' problem, and I *know* how frustrating tracking that one down was. If it shaved a few minutes off of the pain that banging your head against the keyboard brings, I'm happy to have been of service. ;-P

      -Blake