Check if file is loaded completely and then process the file

I need to write a script which checks for files loaded into a folder (files are loaded by ftp from other server) and process the file only if the file is loaded completely.

if the file is not complete in the current run, it must be processed in the next run.

Any suggestions would be welcome
Thanks in advance

How do you know if the file is loaded completely?

Well, if you can mark the last line of the file with something, you could check for that with 'tail -1', and process it if that line exists.

Alternatively, you could get the FTP process to upload a marker file first, then delete that marker file once the main file is uploaded. You could then check for the marker file.

Or, you could watch the size of the file over say a 30 second interval. If the file size has remained static in that time, you could assume that no FTP process is writing to it anymore.

Do any of these suggestions help you?

We had a similar requirement once and we used the third option that cambridge has suggested here... Check the size of the file over a 30 second interval and if the size remains static that means the file has been downloaded successfully...

regards,
Arun.