Linux and Perl, bad interpreter error

I had a perl script that scans an ugly ugly HL7 interface error log that was originally made for AIX 5.3. That server is gone and i copied the script to the new Red Hat server. This is what happened when i tried to run it:



[root@StupidRedHat /]# errorscan
: bad interpreter: No such file or directoryrl


So i used vi to change the # line from #!/usr/bin/perl to #!/usr/local/bin/perl (which perl). But i still get the exact same error message. However, if i run perl using errorscan as an argument it works:



[root@StupidRedHat /]# cd /usr/bin
[root@StupidRedHat bin]# perl errorscan

Enter the path of the log file to be searched:


What else does Linux need to make this work the right way?

Type “which perl” into the command line. That will give you the address of the perl interperter executable that is being invoked when you type “perl errorscan”

ETA: and looking at your post again, you already did this. Nvm

I did, that is how i knew to change the bang line

There might be some characters in the “errorscan” script that’s throwing things off, since you did copy it from a non-linux system. Do a vi -b errorscan and look for things you didn’t realize you were there, or in vi use the :%!xxd command to see it in hex.

I used the -b switch and every end of line had a ^M at the end of it. What is that from? I used ftp and set it to binary mode, should it have been ASCII?

Yeah. Just convert it using dos2unix.



dos2unix errorscan > errorscan_new

./errorscan_new


Yes, you should always use text-mode when transferring scripts for this reason. The ^M characters are carriage-returns (\r). DOS and Windows-based OSes use CRLF (
) for their end-of-lines. Unix-type OSes use LF (
) alone.

The Linux kernel does not take kindly to carriage returns appearing on the #! line, and will interpret them as being part of the filename of the interpreter, which file obviously doesn’t exist. Perl itself is more lenient.

There’s just one thing I don’t understand: Where did the linefeeds come from? I’m pretty sure AIX doesn’t use them any more than Linux does, and FTP won’t add them in binary mode.

maybe he used a Windows machine as intermediary?

Maybe they were there on the AIX box too, except AIX was able to handle them.

I haven’t used AIX in forever tho, so who knows.