start job after complete transfer....

Hi,

I have a situation... I have a script it checks for a file in a folder which comes to the folder every day at specified time...2am to 4 am, once the file is in the polder my process starts...but the problem is the files being placed are huge and it is even taking half an hour for the file to complete transfer from other side, but even before transfer is complete my script wakes up and detects file which is still in process of transfer and triggers the job and my job is failing...because it does not have the access to the file or it has write lock on it....how to overcome situation.....? Here is my script..

#! /usr/bin/sh
count=1
cd /to/path/of/file
while true
do
 if [ -f file.txt ]
  then
    start my job
    exit 0
   fi
if [ $count = 4 -o $count = $8 -o $count = 12 ]
then
 mail -s " file not recieved....."
fi
if [ $count = 16 ]
then 
mail -s "Final alert File not recieved..."
exit 1
fi
let count=count+1
done

I could think of checking of file size aswell but that adds more time on my script...is there any way of doing it easily....

Thanks,

A common solution to this is to have a trigger file transmitted to the folder after the large file. Then your script checks for the trigger file before proceeding.

Another method for files that have a known format where the last record of the file is a trailer record, which can also be easily be tested.

Thanks a lot that helps.