GGI works and then doesn't work--global replace

Sivakatirswami katir at hindu.org
Mon May 20 06:30:33 EDT 2002


There's a mystery with the following CGI running on a SPARC-Solaris -- two
questions.

FYI The intent is to have a global search and replace function for strings
in HTML files.

1-Mystery... I ran this script using "GET" and about 3 minutes later, after
processing  792 files it returned "Done." and a manual check of files showed
that it had succeeded in processing the file.

  Then, a few minutes later I changed the text in the string to be replaced
and, inexplicably, the server returns a configuration error and the error
log indicates "premature end of script headers" which I know to be a generic
error message that tells one very little about what actually went wrong.
Any one have any ideas why it could work the first time and fail the next
time? 

2) This script is a little slower than expected running on such a powerful
CPU... though perhaps my expectations are too high... but, is there a better
strategy, perhaps issuing shell command to get UNIX to do the work?  Just
the directory walk itself to get a file list was fairly time consuming.


#!/export/[snip]/www/public_html/cgi-bin/mc


global gHierList,gMainFolder

on startup
set the directory to "../" ## gets us up and out of /cgi-bin/
put the directory into gMainFolder
  directoryWalk gMainFolder

repeat for each line y in gHierList
## following line does the work.
Replace "copyright (C) 2001 Himalayan Academy" with \
     "copyright (C) 2002 Himalayan Academy" in URL ("file:"&y)
end repeat 
put "done" into buffer
    put "Content-Type: text/plain" & cr
    put "Content-Length:" && the length of buffer & cr & cr
    put buffer
end startUp


on directoryWalk whatFolder

  set the itemDel to "/"
  set the directory to whatFolder
  put the files into temp
filter temp with "*.html"
  add the number of lines of temp to tCount
  sort temp
  repeat for each line x in temp
    put whatFolder & "/" & x & cr after gHierList
  end repeat
  put the folders into tDirList
  sort tDirList
delete line 1 of tDirList
  repeat for each line x in tDirList
    if (x = ".."  or x = "webmaster") then next repeat
   directoryWalk (whatFolder & "/" & x)
end repeat




More information about the metacard mailing list