0

It's weird that my shell script in website show the whole source code, not the html that I want. My script is:

#!/bin/sh

echo "Content-type: text/html"
echo ""

cat << EOF
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <title>test</title>
        <link type="text/css" href="../jquery/css/redmond/jquery-ui-custom.min.css" rel="stylesheet">
        <script type="text/javascript" src="../jquery/js/jquery.min.js"></script>
        <script type="text/javascript" src="../jquery/js/jquery-ui-custom.min.js"></script>

        <script type="text/javascript">
        //<![CDATA[


        if(verifiedUser == "")
            window.top.location.href = "/";


        //]]>
        </script>
    </head>

    <body>
        <table align="center">
            <tr><td align="right">Product Name</td><td align="left">
            </td></tr>
            <tr><td align="right">Hardware Version</td><td align="left">
            </td></tr>
            <tr><td align="right">Firmware Version</td><td align="left">

            </td></tr>
        </table>
    </body>
</html>
EOF

and what the .cgi file show is just that code! My cgi file is in the same directory of the html files, because the main directory is in /mnt, so not put in /home/www/cgi-bin/ as usual.

What's the reasonable problem can cause this situation?

Any advice appreciated!

1
  • 1
    It sounds like the server isn't running the script, it's just returning it as a static file. Are you sure the server is configured to run .cgi files? Commented Jun 3, 2014 at 11:00

2 Answers 2

1

AFAIK, the separator between header section & the html data should be a blank line in CRLF format.

Try this:

echo -e "Content-type: text/html\r"
echo -e "\r"

cat << 'EOF'
---remaining HTML data---
EOF

Note: I have also changed cat << EOF to cat << 'EOF' to prevent any variable expansion. Revert it if variable/command expansion is needed.

Sign up to request clarification or add additional context in comments.

Comments

0

@Barmar has the right idea - Your server is very likely not configured to run those files, but rather send the file directly to the client. So it's a configuration issue, not a programming one.

1 Comment

Thank you guys! I notice that the original file that my co-worker gave me can run the cgi, so maybe the problem is that I changed the original file not properly, so that the cgi cannot be run :O

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.