Bash (CGI) error

Bash (CGI) error

Posted by: jonks
Posted on: 2006-02-04 00:59:00

Does anyone know why this (simple) bash script produces
"Premature end of script headers" in the apache error log?

The script is saved as test.cgi. file chmod=655. Dir=655.
I cannot see anything what is wrong with it. (OK - it's 1am at the moment - give me a break!)


#!/bin/bash
echo "Content-Type: text/html"
echo ""
echo "<html>"
echo "<head><title>Bash as CGI</title></head>"
echo "<body>"
echo "<h1>Hello world</h1>"
echo "</body>
echo "<html>"


Re: Bash (CGI) error

Posted by: psross
Posted on: 2006-02-04 03:33:00

CGI scripts are executed as your user. The script therefore needs to have user read and execute permissions (700). There is no need to allow group and other access.

You are also missing a close quote on the second to last line.

Re: Bash (CGI) error

Posted by: matttail
Posted on: 2006-02-04 06:04:00

Also, you might want to close the html tag in the last line.



-Matttail

Re: Bash (CGI) error

Posted by: jonks
Posted on: 2006-02-04 07:24:00

Thanks both of you.
Now that I've woken up after a good nights sleep, it was obvious 8))

Tags: echo echopremature end of script headersecho content typeapache error logcgi errortest cgibash scripttext htmlchmodsaved