Author Topic: Apache and CGI  (Read 2674 times)

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Apache and CGI
« Reply #15 on: 26 July 2002, 06:53 »
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 ]

Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
Apache and CGI
« Reply #16 on: 26 July 2002, 07:05 »
i got that script from an ikonboard download.
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Apache and CGI
« Reply #17 on: 26 July 2002, 07:59 »
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.
Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
Apache and CGI
« Reply #18 on: 26 July 2002, 08:27 »
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?
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Apache and CGI
« Reply #19 on: 26 July 2002, 21:22 »
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: [Select]

If it has a carriage return it will look like this:

Code: [Select]

The first example is UNIX format, the second is DOS format.

[ July 26, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
Apache and CGI
« Reply #20 on: 26 July 2002, 21:52 »
after doing the 'tr' above it deleted all the content in YaBB.cgi
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Apache and CGI
« Reply #21 on: 26 July 2002, 10:02 »
Notice in my "tr" comand I use two different names. If you write your output to the same filename you are reading the input from you will indeed erase the contents of the file.  So it is a two step process if you use the "tr" method.  That is, do the "tr" command and send the output to a temporary file, then "mv" the temporary file over the original file.  Use the "vim" method if you don't want to have to do two steps, or write a script that goes something like this:

Code: [Select]

and name it "dos2unix", make it executable and put it in your path. Of course you could also download and install the real "dos2unix" which will probably checks a few more things and come with some documentation. But it ultimately performs the same task.

Here's the RPM:
http://www.rpmfind.net/linux/rpm2html/search.php?query=dos2unix

Use the one for RedHat 7.2 i386.

[ July 26, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
Apache and CGI
« Reply #22 on: 26 July 2002, 10:37 »
Of course i have dos2unix.
i installed every fucking program (and had to remove lots) on the RedHat installation CDROM. I chose every package.

I got YaBB working now.. no help to their fucking installation guide which made me learn all about permissions again.
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
Apache and CGI
« Reply #23 on: 26 July 2002, 23:00 »
what error?
you must re-register since this is a completely different board.
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'