File write begin/end, recording time

Hello all,

How can I find out the start and end of the writing file in the directory or recording time for writing file?

I have a directory where small ~ 1*MB temporary files are written.
After the end of the record, they are retrieved and erased.
I can only find out that the files are being written there.

while true; do ls --full-time temp | grep -v "insgesamt 0"; done

Thanks!

Hello mrAibo,

You might get some joy from the output of the stat command. The file is Modified as it is created and Changed as the content is written, however this might not be safe for a polling process to be sure the file is complete.

What is the overall goal of the process you are looking to automate?

It might be safer to write a flag file when the real IO has completed, e.g. the file name might be abc123def456.output and this grows as the data is written/transferred. At the end of the writing process, just touch abc123def456.output.complete A reading process should look for files ending .complete and only then attempt to work with the real data file. Of course, there is then an extra file to tidy away and an extra IO, but the time taken should be negligible.

Does this better suit what you need, or have I missed the point?

Kind regards,
Robin

Hello rbatte1,
I suppose that the other Server transfers the files too slow to our Server. The lag is ~3Sec., after file is ready it will archive and erased from directory.
The supporter on other side said that he see no problem. Now I have to approve that we are not guilty.
Sorry for my English:(

Solved with Inotify tools.

inotify (in Linux) is most efficient.
You can also poll the file with fuser (or lsof).

file=tempfile
if [ ! -f $file ]
then
  echo "$file is not present"
elif pids=$(fuser $file 2>/dev/null); [ -z "$pids" ]
then
  echo "nobody reads or writes to $file"
else
 echo "$file is accessed by PIDs" $pids
fi