Operating Systems > Linux and UNIX
Apache and CGI
voidmain:
Ok m0r, I have made a copy of your test script and fixed it so it works. Look at:
http://chatroom.fuckmicrosoft.com:8000/bobhub/cgi-bin/perl_test2.cgi
Couple of things. First, you can't edit your Perl scripts on a Win* machine (you sick puppy) and then transfer the scripts to your *NIX machine and have them run without stripping the carriage returns '\r'. More specifically, the first line "#!/usr/bin/perl" can not be terminated with "\r\n", only "\n". DOS/Win terminates lines with a carriage return and a line feed. Unix terminates lines with only a line feed. You can strip them by transferring them to your *NIX box using FTP in "ASCII" mode or once they are on your server you can do this:
tr -d '\r' < script.cgi > newscript.cgi
Secondly, the number of newlines "\n" are key in the header output between the "Content-Type: text/html" and the "<HEAD>" tag. You had:
print "Content-Type: text/html\n\n";
which is good, and then a blank line in front of your "<HTML>" tag. I removed the blank line and it worked.
And of course, the file needs to be readable and executable by the user that Apache runs under.
[ July 25, 2002: Message edited by: VoidMain ]
Master of Reality:
i got that script from an ikonboard download.
voidmain:
So you are saying you downloaded it directly to your server or did you download it to your Winblows box and transfer it to the server from there? Either way, either the '\r's were in the file and they can't be. It's the difference between a DOS text file and a *NIX text file. If you downloaded it directly to your server then the smucks who wrote it wrote it on an M$ box.
Master of Reality:
that was ikonboard... and now something tells me i dont want to use it.
After i dled/unzipped/installed YaBB i was told to run YaBB.cgi. It say ": bad interpreter : no such file or directory"
uhhh... what does this mean?
voidmain:
That means the file needs to be stripped of the '\r's. You can do it as I mentioned above or you download a "dos2unix" script from the net (it does basically the same thing I showed you with the "tr" command above).
The first line in the script "#!/usr/bin/perl" *must* end with a '\n' only, not a '\r\n'.
Another easy way to convert it to UNIX format is to open the file in vim. If you do a ":w" it will write the file and if it shows "[dos]" on the bottom line it is in DOS format and will fail with the error message you posted. You can convert it to UNIX (strip the carriage returns) right in vim by doing a ":set fileformat=unix" then type ":w" and it should write the file without the carriage returns and not display a "[dos]" on the bottom line. It should then run properly.
Another way to check if there is a carriage return on the first line is do this (replace "script.cgi" with the name of the Perl CGI file you want to check):
head -1 script.cgi | od -c -w18
which should produce this:
--- Code: ---
--- End code ---
If it has a carriage return it will look like this:
--- Code: ---
--- End code ---
The first example is UNIX format, the second is DOS format.
[ July 26, 2002: Message edited by: VoidMain ]
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version