CGI (Common Gateway Interface), is a method of embedding programs within your web server. A very simple example is shown below :-

#!/bin/sh
echo Content-type: text/plain
echo
echo 10 print "Hi There"
echo 20 goto 10
echo Hello there I see you saw my page at $HTTP_REFERER and came for a look.
echo You are using $HTTP_USER_AGENT as a browser.
echo $HTTP_USER_AGENT >> agentfile.txt
echo \<a href=\"http://mydomain.com\"\> Home \</a\>

Notice the \ escapes, the blank echo after the content-type line. Also If you want to use agentfile.txt line, remember to create a blank file first, and then use ‘$ chmod 755 agentfile.txt' to ensure that the permissions are set.

The full use of ‘cgi' can not be covered on our server, but we have put together an important checklist for those encountering problems when trying to run their scripts on the NetCulture site.

Checklist :-

Your script files must have the execute permissions set. This can be done using the command ‘$ chmod 755 scriptname'

The web server dictates that scripts must end in ‘.cgi' to ensure execution.

Any scripts that do not have the ‘Content Type' tag as the first line must be named ‘nph-scriptname.cgi'. The ‘nph-' stands for non-parsed-headers.

Perl 5 is located as ‘/usr/bin/perl' or ‘/usr/local/bin/perl'. You should make sure that the script header refers to the correct Perl location.

If you find that your Perl scripts do not run, check to ensure that the file was not uploaded using the BINARY format in ‘ftp'. The reason for this is that DOS based systems use ^M^L as an end of line definition, Unix systems do not. You can check this using either ‘vi' or ‘cat' to look at the file, if the end of lines show a ^M that will be the cause of the problem. Remember to upload all scripts using the TEXT format.

Scripts created for Perl 4 will need to have the characters ‘@' and ‘$' escaped to work correctly with Perl 5. This can be done using the backward slash as in ‘\@' and ‘\$'.