Reputation: 20956
Let say I have a file.log
and some process put logs there while processing the data.
I want to wait for data to be processed.
How could I write simple script to wait for process to stop populate the log file for 3 minute for example?
Upvotes: 1
Views: 89
Reputation: 6517
I assume you want to wait until such a time when the file's modification date is at least some set amount in the past.
With the usual Unix tools, we could use find -mmin
to test if the file is old enough, and loop until it is:
while tmp=$(find -name filename -mmin +3) ; [ -z "$tmp" ] ; do
sleep 10
done
Assuming the find
can ever match at most one file, the output will be empty if the file is too young, and the loop repeats.
On Linux, you could also use inotifywait
to get notified immediately when the file is closed, but that only works if there is only one process writing to it, and it doesn't close and re-open it while working.
Upvotes: 1