I have a device that writes logs to a logfile on an nfs mountpoint. It writes to the same logfile "forever" resulting in a file that gets insanely large.

I have a script (running on another nfs client) that does a log rotate, so that I have smaller daily logfiles. When I'm done with the log rotate, I would like to force the device's file pointer to the start of the file so that the device would start writing at the start of the logfile again.

This would require the nfs client doing the log rotate doing, "something" (not sure what) to the log file that would force the other nfs client (the writing device) to set its file pointer to the start of the file.

My understanding is that this can't be done because each nfs client independently maintains it's own file pointers.

Am I wrong? Can this be done?

1 Answer 1


Usually log rotation requires killing the process which is writing the log file. The man page for the logrotate command might be helpful.

Assuming the device that's doing the writing is also a Unix or Linux type of system, the process writing the file will continue to write data to the file until it closes the file. Even if the file is removed or renamed on the NFS server, the process will continue to write to it.

My understanding is that this can't be done because each nfs client independently maintains it's own file pointers.

Your understanding is generally correct, but the same would hold true even if all of the processes were on the same machine and NFS was not involved.

It's how the i/o subsystem works on Unix/Linux systems. You cannot force the modification of a file pointer in a process.

However if you could place a proxy in between the NFS client and server, then possibly the proxy could buffer the data or redirect to a temporary file for enough time to close the file and rotate. An example of an NFS proxy would be NFSex http://nfsex.sourceforge.net/ though it implements NFS read-ahead and write-behind for Windows, the diagrams on that web page show the idea. It seems plausible that someone my have already done this, but I'm not aware of any implementation.

  • That was my understanding also, re: modification of a file pointer - I was hoping I was wrong, or there was some trick that I was not aware of. The, "device" that I am talking about is a terminal concentrator that can't just be rebooted. Maybe something like fuse-nfs could be tweaked so that a continuously writing client's data comes out a pipe somewhere else. That would suit my purposes - and maybe someones done it already. Commented May 16, 2019 at 17:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .