On Fri, 2008-04-11 at 15:58 +1000, Peter Hardy wrote:
> On Fri, 2008-04-11 at 15:06 +1000, david wrote:
> > while inotifywait -e close somefile ; do
> >     <lots of stuff>
> >     rm foo/*.tif
> > done
> > 
> > 
> > The problem is that i need to make sure that foo/*.tif have closed
> > before I remove them, or strange things happen.
> > 
> > I don't know what the names of the tif files are going to be, although I
> > know they will in directory foo/
> > 
> > Is there a way of waiting until all files in foo/ are closed?
> 
> lsof will work as long as foo/*.tif doesn't overflow your command line
> length.
> 
> while inotifywait -e close somefile ; do
>       <stuff>
>       while lsof foo/*.tif > /dev/null 2>&1 ; do
>               sleep 1
>       done
> done
> 

Thanks everyone.
For the archive, this is where I finished up - seems to work so far:

while inotifywait -e close somefile; do
        <some stuff, including a short sleep [1] >
        while lsof foo/*.tif > /dev/null ; do
                sleep 10                # because they are big files
        done
        rm foo/*.tif
done

[1]
I wonder about timing issues. "somefile" is a 3 byte counter which is
the first thing updated by another program, which then creates the tif
files. I want my script to do it's thing after all that.

What happens if the lsof test happens before the tif files are first
opened for writing? Am I worrying too much?

I've put a sleep into <some stuff> in case that's a problem. For my job
it doesn't matter if there is a sleep in there.

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to