[Gloucs] "Is the file completed" in bash

Glyn Davies glynd at walmore.com
Wed Jul 13 20:03:10 BST 2005


Paul Broadhead wrote:

>Glyn Davies <glynd at walmore.com> wrote:
>
>  
>
>>What's the best way in a script of determining that a file has been 
>>finished being written to before going on to process it? I'm writing a
>>script to rename user backup files to something more meaningful but 
>>obviously, I don't want to rename a file part way through its
>>creation.
>>    
>>
>
>Hey a bash question.  Unfortunately I don't know the answer ;-(
>
>However, the command stat may help; you can get information about
>modification times, file sizes etc.  You save the output of "stat
>thefile | grep ^Modify:" then compare this with the output a few seconds
>later, proceeding if the stat output is the same.
>
>Alternatively, the find command also has filters for modification times.
>The following command only finds files, with the .gz extension, that
>have not been changed in the last minute:
>
>find . -name "*.gz" ! -cmin 1 -print
>
>Regards,
>Paul
>
>  
>
Thanks everyone for the ideas.

I knew find could do modification times and the like but always found it 
a a bit of a pain. In fact, I think the find I used in the past may not 
have had cmin The find command avove is peachy for what I want (minus 
the !).

I liked the fuser idea but alas you need to be root. Didn't seem to have 
lsof.

Thanks again all.

-- 
Best Regards
Glyn Davies




More information about the gloucs mailing list