# Ruby cgi script

**URL:** <https://rubytalk.org/t/ruby-cgi-script/50477>\
**Category:** ruby-talk\
**Created:** [2 December 2008 10:54 UTC](https://rubytalk.org/t/ruby-cgi-script/50477 "2008-12-02T10:54:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZippySwish](https://avatars.discourse-cdn.com/v4/letter/z/50afbb/32.png) [@ZippySwish](https://rubytalk.org/u/ZippySwish)\
**Post date:** [2 December 2008 10:54 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/1 "2008-12-02T10:54:28Z")

</div>

I put "script.rb" into the cgi-bin folder of my webhost, but nothing's  
happening. What am I doing wrong?

script.rb containing for example:

#!/usr/bin/ruby  
puts "\<html\>\<body\>\<p\>Hello World!\</p\>\</body\>\</html\>"

(the path to ruby is correct according to the helpfiles from my  
provider)

---

<div class="post-metadata">

**Author:** ![Thomas\_P](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Thomas\_P](https://rubytalk.org/u/Thomas_P)\
**Post date:** [2 December 2008 11:22 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/2 "2008-12-02T11:22:07Z")

</div>

[http://www.linuxjournal.com/article/8356](http://www.linuxjournal.com/article/8356)

> **···**
>
> 2008/12/2 ZippySwish \<fischer.jan@gmail.com\>:
> 
> > I put "script.rb" into the cgi-bin folder of my webhost, but nothing's  
> > happening. What am I doing wrong?
> 
> --  
> Thomas Preymesser  
> thopre@gmail.com
> 
> > **[Google Sites: Sign-in](https://accounts.google.com/v3/signin/identifier?continue=https%3A%2F%2Fsites.google.com%2Fsite%2Fsites%2Fsystem%2Ferrors%2FWebspaceNotFound%3Fpath%3D%2Fthopre%2F&followup=https%3A%2F%2Fsites.google.com%2Fsite%2Fsites%2Fsystem%2Ferrors%2FWebspaceNotFound%3Fpath%3D%2Fthopre%2F&ifkv=ASKXGp1vtT9UmenTNpWMPpSVu8mqXRMH4thGkvq8i0EsWOQdW0yLu1JBVRcFaCtAfzzjuOTbXd_10A&passive=1209600&service=jotspot&flowName=GlifWebSignIn&flowEntry=ServiceLogin&dsh=S2080497493%3A1707133807912073&theme=glif)**
> >
> > Access Google Sites with a personal Google account or Google Workspace account (for business use).
> 
> > **[thopre](https://thopre.wordpress.com/)**
> >
> > Entwicklungen für die Bühne des Lebens

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [2 December 2008 13:27 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/3 "2008-12-02T13:27:03Z")

</div>

ZippySwish wrote:

> I put "script.rb" into the cgi-bin folder of my webhost, but nothing's  
> happening.

I very much doubt "nothing" is happening. But perhaps you don't see  
anything in your browser.

A better way to test from the client machine is to use telnet instead of  
a web browser. Type the following:

telnet [www.yourhost.com](http://www.yourhost.com) 80  
GET /cgi-bin/script.rb HTTP/1.0  
Host: [www.yourhost.com](http://www.yourhost.com)  
\<blank line\>

and see what response comes back. Paste it here if it doesn't make  
sense.

> script.rb containing for example:
> 
> #!/usr/bin/ruby  
> puts "\<html\>\<body\>\<p\>Hello World!\</p\>\</body\>\</html\>"

Often you will need

puts "Content-Type: text/html"  
puts  
puts "... rest of output ..."

That may or may not be the problem. You'll need to be more specific  
about what you see.

You may also need to set the execute bit on script.rb (chmod +x  
script.rb - but if you're on a hosted service you may be able to do this  
over FTP/SFTP with a 'site chmod' command. Consult your service  
provider)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![ZippySwish](https://avatars.discourse-cdn.com/v4/letter/z/50afbb/32.png) [@ZippySwish](https://rubytalk.org/u/ZippySwish)\
**Post date:** [2 December 2008 16:19 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/4 "2008-12-02T16:19:25Z")

</div>

Thanks everyone so far, I'll try some more

---

<div class="post-metadata">

**Author:** ![ZippySwish](https://avatars.discourse-cdn.com/v4/letter/z/50afbb/32.png) [@ZippySwish](https://rubytalk.org/u/ZippySwish)\
**Post date:** [2 December 2008 19:04 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/5 "2008-12-02T19:04:28Z")

</div>

Well, telnet can't get a connection for some reason, but what I mean  
by "nothing's happening" is I put

[http://www.myhost.com/cgi-bin/script.rb](http://www.myhost.com/cgi-bin/script.rb)

and get a nothing but white space in return.

The file is set to executable.

I emailed my provider but it may be a while before I get an answer.

---

<div class="post-metadata">

**Author:** ![Hassan\_Schroeder](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/hassan_schroeder/32/1838_2.png) [@Hassan\_Schroeder](https://rubytalk.org/u/Hassan_Schroeder)\
**Post date:** [2 December 2008 20:08 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/6 "2008-12-02T20:08:58Z")

</div>

> Well, telnet can't get a connection for some reason,

That's bad -- you should figure that out; direct access via telnet is a  
useful troubleshooting tool.

> but what I mean  
> by "nothing's happening" is I put
> 
> [http://www.myhost.com/cgi-bin/script.rb](http://www.myhost.com/cgi-bin/script.rb)
> 
> and get a nothing but white space in return.

What do your logs say?

And if this is bypassing any server handling, you need to provide the  
appropriate HTTP headers, not just the HTML...

> **···**
>
> On Tue, Dec 2, 2008 at 11:04 AM, ZippySwish \<fischer.jan@gmail.com\> wrote:
> 
> --  
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [2 December 2008 21:36 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/7 "2008-12-02T21:36:25Z")

</div>

ZippySwish wrote:

> Well, telnet can't get a connection for some reason

Then investigate. What \*exactly\* do you see when you try a telnet?

If you post the real hostname here, we can try it for you.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Chad\_Perrin1](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Chad\_Perrin1](https://rubytalk.org/u/Chad_Perrin1)\
**Post date:** [4 December 2008 17:24 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/8 "2008-12-04T17:24:03Z")

</div>

Are you sure the hosting provider actually allows telnet connections?

You probably shouldn't use telnet anyway -- try SSH instead. My first  
rule when looking at shared hosting providers is that I won't use one  
that doesn't allow me encrypted remote access. Since telnet isn't  
encrypted, a man-in-the-middle attack (among other means) can be used to  
intercept your username and password when you try to log in via telnet.

> **···**
>
> On Wed, Dec 03, 2008 at 04:04:28AM +0900, ZippySwish wrote:
> 
> > Well, telnet can't get a connection for some reason, but what I mean  
> > by "nothing's happening" is I put
> > 
> > [http://www.myhost.com/cgi-bin/script.rb](http://www.myhost.com/cgi-bin/script.rb)
> > 
> > and get a nothing but white space in return.
> > 
> > The file is set to executable.
> > 
> > I emailed my provider but it may be a while before I get an answer.
> 
> --  
> Chad Perrin [content licensed PDL: [http://pdl.apotheon.org](http://pdl.apotheon.org) ]  
> Quoth Albert Camus: "An intellectual is someone whose mind watches  
> itself."

---

<div class="post-metadata">

**Author:** ![ZippySwish](https://avatars.discourse-cdn.com/v4/letter/z/50afbb/32.png) [@ZippySwish](https://rubytalk.org/u/ZippySwish)\
**Post date:** [3 December 2008 20:29 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/9 "2008-12-03T20:29:28Z")

</div>

Hey,

turns out my End Of Line characters had the wrong format.

Problem is fixed now.

Thanks everyone!

---

<div class="post-metadata">

**Author:** ![Hassan\_Schroeder](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/hassan_schroeder/32/1838_2.png) [@Hassan\_Schroeder](https://rubytalk.org/u/Hassan_Schroeder)\
**Post date:** [4 December 2008 17:54 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/10 "2008-12-04T17:54:55Z")

</div>

Dude, totally missing the point -- the idea is to use your local telnet  
client to test the connection to \*port 80\* and directly examine the  
http server's response.

Nothing to do with logins, passwords, etc.

> **···**
>
> On Thu, Dec 4, 2008 at 9:24 AM, Chad Perrin \<perrin@apotheon.com\> wrote:
> 
> > Are you sure the hosting provider actually allows telnet connections?
> > 
> > You probably shouldn't use telnet anyway -- try SSH instead.
> 
> --  
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---

<div class="post-metadata">

**Author:** ![Michael\_Monaghan](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@Michael\_Monaghan](https://rubytalk.org/u/Michael_Monaghan)\
**Post date:** [4 December 2008 18:09 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/11 "2008-12-04T18:09:21Z")

</div>

Alternatively, the Firefox WebDeveloper plugin allows you to view the http  
response.

~m

> **···**
>
> On Thu, Dec 4, 2008 at 12:54 PM, Hassan Schroeder \< hassan.schroeder@gmail.com\> wrote:
> 
> > On Thu, Dec 4, 2008 at 9:24 AM, Chad Perrin \<perrin@apotheon.com\> wrote:
> > 
> > \> Are you sure the hosting provider actually allows telnet connections?  
> > \>  
> > \> You probably shouldn't use telnet anyway -- try SSH instead.
> > 
> > Dude, totally missing the point -- the idea is to use your local telnet  
> > client to test the connection to \*port 80\* and directly examine the  
> > http server's response.
> > 
> > Nothing to do with logins, passwords, etc.
> > 
> > --  
> > Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---

<div class="post-metadata">

**Author:** ![Chad\_Perrin1](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@Chad\_Perrin1](https://rubytalk.org/u/Chad_Perrin1)\
**Post date:** [5 December 2008 01:00 UTC](https://rubytalk.org/t/ruby-cgi-script/50477/12 "2008-12-05T01:00:31Z")

</div>

You're right -- I missed that point, probably because I tend to use other  
tools for the same purpose.

> **···**
>
> On Fri, Dec 05, 2008 at 02:54:55AM +0900, Hassan Schroeder wrote:
> 
> > On Thu, Dec 4, 2008 at 9:24 AM, Chad Perrin \<perrin@apotheon.com\> wrote:
> > 
> > \> Are you sure the hosting provider actually allows telnet connections?  
> > \>  
> > \> You probably shouldn't use telnet anyway -- try SSH instead.
> > 
> > Dude, totally missing the point -- the idea is to use your local telnet  
> > client to test the connection to \*port 80\* and directly examine the  
> > http server's response.
> > 
> > Nothing to do with logins, passwords, etc.
> 
> --  
> Chad Perrin [content licensed PDL: [http://pdl.apotheon.org](http://pdl.apotheon.org) ]  
> awj @reddit: "The terms never and always are never always true."
