tags:

views:

44

answers:

3

I've seen a few questions/answers here that deal with this, but none really give me an answer/solution.

I've got a Clipper system writing csv files to a Windows directory. I have a perl script running on a Linux server that is reading a mount of that Windows directory and importing the files to a database.

Right now we're using flag files to indicate when a csv is no longer being written to; the flag files gets written after the csv is done. I'd really rather just get what I need from the csv itself, but I can't seem to find a way to tell when the file is open and being written to.

lsof doesn't seem to answer my need. I've tried using flock and open the file with an exclusive lock, thinking it might throw an error if the file is being modified, but it doesn't.

Any thoughts?

A: 

According to linux's man page for flock:

flock() does not lock files over NFS. Use fcntl(2) instead: that does work over NFS, given a sufficiently recent version of Linux and a server which supports locking.

Have you tried using fcntl()? Googling I find a few examples of people using fcntl with CIFS.

Andrew E. Falcon
A: 

It may not work since you're mounting to Windows, but maybe inotify would help.

cadwag
A: 

If inotify does not work, use Poor Man's Polling: if modification time is older than two seconds, the file is finished writing.

daxim
It takes too much time. We might feed through 10 thousand+ files in a day. 2 seconds for each add a lot of time to the processing. I tested 690 files and it took about 25 minutes to import them. Using the flag files, it only took about 50 seconds.
Henry