From: bradjpeek Date: 2009-05-08T03:40:09+09:00 Subject: Re: How can I trim top of file w/o disrupting other writers? On May 6, 9:15 pm, Julian Leviston wrote: > On 07/05/2009, at 9:35 AM, bradjpeek wrote: > > > As a way to learn ruby, I wrote a method to trim the first "n" lines > > from a log file.   I had planned to use it on a series of log files > > that are constantly growing.   However, some of the programs that are > > appending to these logs don't tolerate the somewhat brute-force method > > I'm using, which is: > > > 1) Write the lines I want to keep to a temp file > > 2) Rename the temp file to the original log file name > > > This works fine for some log files, but others stop receiving log data > > after I run my program.   I suspect it is because they have the file > > open and don't notice that the inode (or some other pointer to the log > > file) has been pulled out from underneath them. > > Why can't you simply open the file itself for read write then replace   > the contents? That's worked fine for me before > That worked. Thanks for the embarassingly obvious answer. Actually, that occurred to me when I first wrote the script and I can't remember why I chose the rename approach.