I have shell script which waits for some files to arrive from remote machine, when it arrives, it cats them to a new file. For that I am using a while loop,like following:while truedo    if [ $(find ../Test_Data/local_enc* | wc -l) -eq 2 ]    then            break    else            sleep 0.001    fidonecat ../Test_Data/local_enc* > ../Test_Data/All_Enc_Coords.txtThe problem is All_Enc_Coords file is written sometimes, and sometimes not written. I think this is because, find function returns some value, even when the file has no data in it.How to ensure that the files have been written successfully?? and how to specify it in the while loop. That means, I want all the files to be written completely and then cat them?.. I used sleep 1 before cat and found that the file is written completely, but is there any way round to check this??
How to know if a file has been written completely?
bash;shell
You can use a test case.while [[ ! -e ../Test_Data/All_Enc_Coords.txt ]]; do  if [ $(find ../Test_Data/local_enc* | wc -l) -eq 2 ]; then    cat ../Test_Data/local_enc* > ../Test_Data/All_Enc_Coords.txt  else    sleep 0.001  fidoneAs per the comments, if you were checking for the file containing data before writing, you could use:while [[ ! -s ../Test_Data/All_Enc_Coords.txt ]]; do  if [ $(find ../Test_Data/local_enc* | wc -l) -eq 2 ]; then    cat ../Test_Data/local_enc* > ../Test_Data/All_Enc_Coords.txt  else    sleep 0.001  fidone