Implementing CGI Scripts: Simple Search Exercise ( 7 May 2008)
In this exercise, you're going to retrieve a CGI script from an archive, install it into your account on Grace, and modify the HTML form that accesses it.
We'll be using a script from Matt's Script Archive called Simple Search, which is used to search the text of documents in a specified directory. Go to the site and download the search.pl script and the search.html file from that site You should also review the documentation for the script.
Part 1: Creating the Directory to be Searched
Begin by creating a new directory in your www directory on Gibson, and call the new directory "searchme". Make sure permissions are set to 755 to allow reading.
Put a few HTML files in the directory--each needs to have only a few lines of text, but put different text in each one.
Part 2: Configuring and Installing Simple Search
You'll be installing the search script into the same directory where you placed the first.cgi script from the last exercise. The permissions should already be set properly on that directory.
Because Gibson requires that CGI files be named with a .cgi extension, you will need to rename search.pl as search.cgi. Then open search.cgi so that you can edit the necessary variables.
The first line of the file needs to show the location of perl on the server. The default line shown in the script will work.
After that, you need to modify the variables at the beginning of the script.
$basedir should be set to the full UNIX path for your searchme directory. Mine, for example, would be /home/ellics/www/searchme -- but yours will be unique to your UNIX directory path. (Use the UNIX pwd command to find the path if you don't know it.)
$baseurl will be the URL path to the directory--e.g. http://people.rit.edu/~ellics/searchme/
@files specifies which files you want to search. For this exercise, leave it at the default of *.html, which will search all .html files in the searchme directory.
You can edit the $title and $title_url if you want, or leave them at the defaults.
$search_url will be the link to your search form; for this exercise, it will be a file called search.html in the searchme directory (e.g. http://people.rit.edu/~ellics/searchme/search.html for my site).
When you're done, upload the file to your www/cgi-bin directory on Gibson.
Part 3: Adding the Search Form
Open the search.html file you downloaded. This is the form that calls the search script.
In the action attribute of the form, change the URL to your search script (in my case, that would be http://people.rit.edu/~ellics/cgi-bin/search.cgi).
You can leave the rest of the form alone, or modify it aesthetically if you prefer. Upload it to the searchme directory when you're done.
Part 4: Testing Your Script
Load your search form in a browser (http://people.rit.edu/~yourid/searchme/search.html). Try searching for a word that you know is in one of the HTML files you uploaded to the searchme directory. Does it show up?
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)