Need to check whether the source file(FTP'ed file) is completly copied or not such that I can further action on the same. I have created the below script to achieve this by checking for every 10secs to whether file size is same or not but it may create a problem if the file transfer is slow and if file size doesnt changes after 10secs , I may end up with copying the incomplete file.
Appreciate your ideas on the same.
#!/bin/ksh
file_nm=$1
no_of_tries=5
sleeptime=10
curr_file_size() {
ls -l $file_nm | awk '{print $5}'
}
if [ -f $file_nm ]
then
no_of_tries=5
sleeptime=10
for i in `seq $sleeptime`
do
prev_file_size=`curr_file_size`
sleep $sleeptime
if [ $prev_file_size -eq `curr_file_size` ]
then
echo file is copied completly
exit
else
echo file is being copied
fi
done
else
echo file does not exists
fi