Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need a way to determine if a file is done being written to

The situation I'm in is this - there's a process that's writing to a file, sometimes the file is rather large say 400 - 500MB. I need to know when it's done writing. How can I determine this? If I look in the directory I'll see it there but it might not be done being written. Plus this needs to be done remotely - as in on the same internal LAN but not on the same computer and typically the process that wants to know when the file writing is done is running on a Linux box with a the process that's writing the file and the file itself on a windows box. No samba isn't an option. xmlrpc communication to a service on that windows box is an option as well as using snmp to check if that's viable.

Ideally

  • Works on either Linux or Windows - meaning the solution is OS independent.
  • Works for any type of file.

Good enough:

  • Works just on windows but can be done through some library or whatever that can be accessed with Python.
  • Works only for PDF files.

Current best idea is to periodically open the file in question from some process on the windows box and look at the last bytes checking for the PDF end tag and accounting for the eol differences because the file may have been created on Linux or Windows.

like image 966
Khorkrak Avatar asked Jun 18 '10 13:06

Khorkrak


1 Answers

There are probably many approaches you can take. I would try to open the file with write access. If that succeeds then no-one else is writing to that file.

Build a web service around this concept if you don't have direct access to the file between machines.

like image 136
Jeroen Ritmeijer Avatar answered Nov 05 '22 04:11

Jeroen Ritmeijer