[Gllug] Checking if a file has finished being written?

Robert McKay robert at mckay.com
Mon Jan 27 15:03:11 UTC 2003


On Mon, 27 Jan 2003, Andy Young wrote:

> Hi all,
>
> I wonder if anyone can tell me a way to check in a shell script if a file
> has finished being written?
>
> I want to automatically transcode from one type of video to another, but
> there is a likely chance of hitting a file mid write if I just do this on a
> timed basis.

If the process keeps the file open the whole time it's writing, and then
closes it when it's done you could use fuser.

Something like this:

#!/bin/bash
FILE=test
RET=0
while [ "$RET" != "1" ]; do
echo "Waiting for file to stop being used.."
/sbin/fuser -s $FILE
RET=$?
done
echo "pounce!"

Hope that helps,

-Robert.

Robert McKay
Unix Systems Administrator
Accucard Ltd.
tel: 02070732283



-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list