fam
[Top] [All Lists]

Re: FAM notify on "file closed after modification" ???

To: fam@xxxxxxxxxxx
Subject: Re: FAM notify on "file closed after modification" ???
From: Martin Wickman <martin@xxxxxxxxxxx>
Date: Fri, 25 Oct 2002 18:42:29 +0200
References: <200210251642.04950.Mattias.Brunschen@xxxxxx>
Sender: fam-bounce@xxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020827
Mattias Brunschen wrote:

In order to do that my software needs to know when a file is written to disk completely, that is when the process writing down the file (i.e. FTP or the SMB daemon) closes the file.

[...]

> Are there any ideas to implement this "file was closed" notification?

I have the same problem. A workaround is to see if there are any processes keeping the file open. I have done this using 'lsof' on Linux.

Here is a hack which does that. Put it in a while loop:

# Get the list from lsof and figure out which files are "free")
dir=my/input

find $dir -type f -maxdepth 1 -print0 | tee tmp | tr \\0 \\n > tmp2
xargs --null /usr/sbin/lsof -Fnp < tmp | grep '^n' | sed 's/^n//' >> tmp2
sort < tmp2 | uniq -c | grep '^      1' | cut -d1 -f2- | while read f;
    echo $f is free
done


<Prev in Thread] Current Thread [Next in Thread>