San Diego State University
Last updated: 9/12/00
Guide To CGI on ROHAN
Page 3/3



Why Doesn't My Script Work?    [ table of contents ]

There are quite a few things that can potentially go wrong when setting up a CGI script, since doing so requires making several different things work at once: HTML, paths, permissions, variables, and the Perl itself. Choose an option below that best describes your situation:

My Script Won't Work From the rohan% Prompt    or    My Script Won't Work From the Web



My Script Won't Work From the Web    [
top | table of contents ]

Hint: Try running your script from the command line before you troubleshoot from the web-side. It is possible that the script is not being executed correctly on the server. Once you have ruled this out, try the following tips to troubleshoot your HTML code.

First of all, are you linking to the script directly, as in <a href="file.cgi">click</a>, or are you calling it from within another HTML file, as in <!--#exec cgi="file.cgi"-->?

If you are linking to it directly, first make absolutely sure that you spelled the filename right and that the path to the file exists. Try going to the directory in which your CGI is stored, and typing pwd at the command prompt. This will give you the full path to your CGI script.

If the link seems to work but the script itself is not producing the right results or is giving you an error, see the list of common error codes below.

If you are calling the script from within an HTML document, first make sure that the HTML has a .shtml extension. This is important because it tells the server to parse the HTML before serving it to the web browser.

Remember that you must use the path to the script relative to where the HTML is located. If the script is in the same directory as the HTML, then <!--#exec cgi="file.cgi"--> is sufficient. However, if file.cgi is located in another directory, say the parent directory of where the HTML is, you need to specify that in the exec tag: <!--#exec cgi="../file.cgi"-->.



My Script Won't Work From the rohan% Prompt    [ top | table of contents ]

Since perl scripts are executed on ROHAN before they are served to the web browser, many problems need to be diagnosed from the server rather than from the web. To test your script from the server, you need to telnet to ROHAN. On a Windows PC, go to the Start menu and choose Run, then type telnet rohan.sdsu.edu in the box and hit enter. From an Xterm or another UNIX, just type telnet rohan.sdsu.edu from your prompt. Log in with your username and password, then change to your public_html directory.

To run a Perl script from the rohan% prompt, type

where file is the name of or path to your script. If the script is working, you will likely get some output beginning with the line Content-Type: text/html\n\n, or at least containing some familiar HTML tags. It is possible that a script made for the web would output an error message when run from the rohan% prompt, so try running it from the web as well.

Here are a list of some Perl error messages and what they mean:
If you get other error output, try emailing the author of the script and describing the problem and the output you received. You may also want to read the Perl documentation with man perl .



Common HTTP Error Codes    [
top | table of contents ]

403 Access Denied

This error indicates that you do not have the correct permissions set on the file you are trying to access. Make sure that your HTML files are readable by everyone (chmod 644 file.html), and that CGI files and directories are both readable and executable by everyone (chmod 755 filename).

404 File Not Found

This error indicates that the path to an HTML or CGI file is incorrect. Double-check your links. Remember that internal and external paths are different, and that UNIX is case-sensitive so that "WebPage" is different than "webpage".

500 Internal Server Error

You will get a 500 error for the following reasons:
  • If the script is missing the "#!/usr/local/bin/perl" header or it is pointing to the wrong place. Alternately, the path/filename of a library file could be incorrect.
  • If the first line of output from the script is not a valid HTTP header such as "Content-type: text/html/n/n", or if there is no blank line after the header data.
  • If there is a syntax error in your script. Try running it from the command line.

Document contains no data

This error code means that the page your browser is trying to retrieve contains no usable data. Usually this is caused by a CGI script failing to run and thus producing no output. Another possibility is that the server is responding too slowly and the connection has timed out before any data could be sent.

[an error occurred while processing this directive]

This is an error produced when an SSI call has a problem. For our purposes, it usually means that you mistyped the location of your CGI script within the <!--#exec cgi="../file.cgi"--> tag, or made some other typo.



Some Sample CGI Scripts    [ top | table of contents ]

Where Can I Find Additional Resources?    [ top | table of contents ]




© 2000