I know how much everyone loves answering specific tech-support questions in threads, so why not take on this little gem?
I manage a web server. From time to time, we install various CGI scripts. No big deal.
Anyway, I upload my scripts. I chmod them to 0755. The file in question, let’s call “install.pl”.
I’m in the directory in question. I’ll do a ls, and get this result:
<other files, blah blah>
install.pl
So there’s the file. It’s executable. When i try this command:
./install.pl
I get this error:
bash: ./install.pl: No such file or directory
I check the first line of install.pl:
#!/usr/bin/perl
Looks normal to me, but hey, might as well check it. Back at the command line, I execute the following command:
/usr/bin/perl install.pl
And the script runs fine. So here’s my question: why the hell is this happening? The file’s there, its executable, and Perl can even see the file. This has nothing to do with this specific script, since its come up in times past. I can create a blank script beginning with the same Perl path, and it will work fine. Anyone else ran into this in the past, or have any ideas? Even the tech support at the webhost has no ideas.
Well, I’m only running the script manually because Apache refused to run it in the first place. However, Apache will run other scripts, and if I write a little “Hello, World!” script, chmod it exactly as the non-working script, and stick it in the same directory, Apache will run it.
Another thing I thought of: could this possibly have something to do with the different types of line breaks used by Windows/Unix? A long shot, I know, but I’m running out of ideas.
The line breaks could indeed be your problem.
If you have access to a hex editor, look to
see if there is a 0d-0h at the end of each line.
I recall having a similar problem in the past that
was the opposite (windows barfed on the unix file).
Next, check the shebang (#!) line of install.pl. That error usually indicates that the shell can’t find the intepretor. (The No such file is talking about the Perl interpretor, not the script.) Type ‘which perl’ at the command line to find the correct path to perl and alter the shebang line as necessary.
I agree with the earlier replies. When I’ve had this problem it was because of the differing DOS and Unix line-break conventions. DOS uses <CR> <LF> (0Dh 0Ah) and Unix uses just <LF> (0Ah). This means that the first line of your script is being interpreted by Unix as
#!/usr/bin/perl<CR>
which has an extra <CR> character in the filename.
A lot of Unix/Linux installations have a program “dos2unix” which will remove the extra carriage returns. You can also use the Unix standard command “tr”: