Java List wrote:
> Hi,
>
> I'm tring to get my servlet to watch a UNIX log file and do something with
> the results. Using java.io.FileReader and java.io.FileInputStream, it it
> possible to watch the log as it's being created. For any UNIX people, I
> want my servlet to do a "tail -f /logfile" and process the results on the
> fly. The reading I've done on this list and on the java.io classes
> hasn't given me enough info to make it happen. Any input (or links to
> good www sites) to make this work is appreciated.
>
> -Nash
>
A few years ago I looked at the source for one implementation of "tail -f".
All it did was an endless loop like this:
* Attempt to read some bytes from the input file
* If you got any, send them to the output file,
and restart the loop
* If you get an end-of-file indication, sleep for a
little while and restart the loop.
You can certainly do this with standard Java I/O routines. You might even
want to run it as a separate thread, so that you can provide some sort of
graceful shutdown mechanism (like having your main thread set a boolean that
is checked each time through the loop).
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html