Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to check arrival of a file using script?

Status
Not open for further replies.

lutech

Programmer
Jan 25, 2002
16
CA
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?

Thanks in advance,
 
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.
 
One of the ways to do these things are :

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.

CHeers
byk
 
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.

Suggestions are invited.

CHeers
byk


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top