Article Title: tips: compile cgi in a self-made C language to implement search. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. environment
/Usr/local/apache/htdocs/(the file to be retrieved is in this directory)
/Usr/local/apache/temp/(as a transit folder)
/Usr/local/apache/cgi-bin/
2. Place a. out generated by gcc search. c in/usr/local/apache/cgi-bin/, and set the permission to nobody.
.
3. chown-R nobody. nobody/usr/local/apache/temp
4. add the deletetemp permission to/etc/cron. daily to 555.
Rm-f/usr/local/apache/temp /*
5. add a file myupdate permission to/etc/cron. hourly to 555.
Updatedb-U/usr/local/apache/htdocs
6. delete a file slocate. cron in/etc/cron. daily.
Appendix (2 in total ):
1. source code of index.htm
Untitled Document
Enter your query string
2. source code of search. c
# Include
# Include
# Include
# Include
# Include
Int main (int argc, char * argv [])
{
Int fd;
Int status;
Time_t I;
Char cFileName [64];
Char cTempName [64];
Char cBuffer [1024];
Char * p = cBuffer;
Char cContent [10240];
Char * data;
Char keyword [1024];
Data = getenv ("QUERY_STRING ");
If (data = NULL)
{
Printf ("Content-Type: text/html ");
Printf ("not found! ");
Exit (1 );
}
Sscanf (data, "keyname = % s &", keyword );
P + = sprintf (p, "locate '% s' | sed-e's # ^/usr/local/apache/htdocs # http: // 129.158.217.223 # '| sed-e's # ^. * $ #&
# '> ", Keyword );
I = time (NULL );
Sprintf (cTempName, "shortd.html", I );
Sprintf (cFileName, "/usr/local/apache/temp/export d.html", I );
Strcat (cBuffer, cFileName );
CBuffer [1024-1] = 0;
System (cBuffer );
Fd = open (cFileName, O_RDWR );
Status = read (fd, cContent, sizeof (cContent)-1 );
Close (fd );
Printf ("Content-Type: text/html ");
Printf (" ", CTempName );
Printf ("Waiting .......................");
Printf ("% s", keyword );
Return 0;
}