Is there any way to check arrival of a file using script?
I have to check a specific directory to process any file arrived in, My problem is how can I know the file is on transfer? How to make sure the file is completely transferred?
One of the easiest ways of doing this might be to include in the script carrying out the transfer a mv at the end to rename the file to it's 'proper' name, which your monitoring script can then test for. For example, send the file over with a name such as 'incomplete' and rename incomplete to 'complete' as the final action of the transfer script. HTH.
i) Add the script as a cron job in the crontab file. This will activate the script after a fixed amount of time (as entered by user).
ii)Along with the script, maintain a data file.
iii) The script logic:
1) Each time script is run, it will check the directory ( with ll (longlisting)for example)
2) For each such file ( use "for"
{
Get the size of file by using "cut -f"
If file_name present in datafile
compare the size obtained now and that in data file
If ( size are same ) // denotes that transfer is complete
do processing
move or delete the file
Else
Make an entry for the file and its size in the data file. //New file
}
Let me know, if you want me to write the actual script.
Another way to ensure that the file has completely arrived can be to FTP another file (a small file with just 1 char will also do) after the Actual file and keep checking for the existence of this file - as soon as this file is detected we know that the 1st FTP must be over. Then delete the small file and move the Actual file to another location. -Vikram Kalsi
----------------------------------------------
We learn most when we have to invent - Piaget
If I am not wrong, then it will be a little difficult I feel.
Reasons :
1) We will have to modify the other code which would not be possible
if that code is not ours.
2)Suppose the other program FTPes a file, then the small marker file and then immediately starts sending another data file. Our code will find the marker and think that both the FTPs are complete.
3) Can be a few more problematic combinations like the one above.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.