|
|
The following CGI script is a fully working search engine for your web pages:
#!/bin/sh echo "Content-type: text/html" echo echo '<html> <head> <title> Search results </title> </head> <body>' argument=`echo "$QUERY_STRING" | sed "s|q=||"` cd /users/homes/me/public_html echo '<pre>' grep -i "$argument" *html */*html | sed -e 's|<|\<|g' -e 's|>|\>|g' echo '</pre>'
Since each search will be using the same file list, it would be more efficient to pre-build the list once, and cache it in a file, and then:cd /users/homes/me/public_html filespec=`find . -type f -name "*html" | tr '\n' ' '` grep -i "$argument" $filespec
(I hope you realise that a heavy-duty search engine would go further and pre-index all the files in advance, rather than grep-ing them on the spot. But simple grep is alright for a personal website.)read filespec < filelist.txt grep -i "$argument" $filespec
But the principle is that in Shell you can rustle up
a quick search engine for your personal pages,
or any subset of them, in a few lines.
e.g. My search engine
in about 55 lines of Shell
(with a C++ input pre-processor for security)
has the above enhancements.
On Internet since 1987.