DreamHost Web Hosting
Discussion Forum


Forums
   >> General Troubleshooting
*Threaded Mode

Subject the simplest shell script--broken  
Posted bygrimholtz (DH New User )
Posted on08/24/06 05:03 PM



Hi,

I'm trying to get bash shell scripts working from the web (not from the shell). I have:

#!/bin/bash
echo 'Content-type: text/html\n\n'
echo '<html><body>hello world</body></html>\n'

I save this as test.cgi. When I navigate to this URL, I get an HTTP 500 (server) error. What am I doing wrong?

Thanks,
grimholtz



Subject Re: the simplest shell script--broken new [re: grimholtz]  
Posted bysdayman (DH Smarty Pants)
Posted on08/24/06 05:09 PM



Have you read the wiki on it?
http://wiki.dreamhost.com/index.php/KB_/_Web_Programming_/_CGI,_PHP_&_Databases#What_is_an_internal_server_error.2C_and_why_doesn.27t_my_CGI_work.3F

My first guess was going to be that you need to chmod 755 your file.

-Scott


Subject Re: the simplest shell script--broken new [re: grimholtz]  
Posted byrlparker (DH Grizzled Veteran)
Posted on08/24/06 05:31 PM



It runs fine from the shell command line, but the error log shows:

[Thu Aug 24 17:08:47 2006] [error] [client xx.xx.xx.xx] malformed header from script. Bad header=<html><body>hello world</body>: /home/xxxx/wwwdirectoryl/test.cgi

[Thu Aug 24 17:08:47 2006] [error] [client xx.xx.xx.xx] File does not exist: /home/xxxx/wwwdirectoryl/internal_error.html

-----try this one --------
#!/bin/bash
echo "Content-type: text/plain"
echo
set
----------------------------

More good cgi stuff on headers is found here
--rlparker





Subject Re: the simplest shell script--broken new [re: sdayman]  
Posted bygrimholtz (DH New User )
Posted on08/24/06 05:55 PM



It wasn't a permissions issue. I've set the permissions to 775. The error in the log is:

Premature end of script headers: test.cgi.

The wiki you linked to says this errors is caused because the header "aren't being printed correctly. here is a basic working script:". However, the basic working script is in perl, and I want to remain in bash for this.

Also, I'm editing this in vi... not ftp'ing so CR/LF shouldn't be an issue. Any other ideas?

Thanks!



Subject Re: the simplest shell script--broken new [re: grimholtz]  
Posted bygrimholtz (DH New User )
Posted on08/24/06 06:14 PM



OK, I see suexec requires it to be 755. I've done that--still get 500 error code. Help!

edit: I figured it out. \n doesn't work as a newline in bash. i need to use "echo" on its own line to get the required CR after headers are complete.

thanks.

Edited by grimholtz on 08/24/06 06:27 PM (server time).



Subject Re: the simplest shell script--broken new [re: grimholtz]  
Posted bygordaen (DH Enthusiast)
Posted on08/25/06 08:40 AM



You can also do something like this:

#!/bin/bash
echo 'Content-type: text/html

<html><body>Hello World!!</body></html>'

Check out Gordaen's Knowledge, the blog, and the MR2 page.


Subject Re: the simplest shell script--broken new [re: grimholtz]  
Posted byemmesel (DH New User )
Posted on08/25/06 02:58 PM



you want to use the "-e" option on the command-line, like so:

#!/bin/bash
echo -e 'Content-type: text/html\n\n'
echo -e '<html><body>hello world</body></html>\n'

otherwise, the "\n" is displayed literally and not as an actual newline character.





*Threaded Mode
Jump to