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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Way To Test If Remotely Transferred File Is Complete 1

Status
Not open for further replies.

CuthbertDibbleGrub

IS-IT--Management
Nov 7, 2003
8
0
0
GB
Files are being transferred to a local directory remotely (from a server with no rsh access). I'm writing a script to loop round every minute or so and action a file once it appears. I need to test whether the file transfer has completed fully.

I was going to...

a. Test that it's there with 'if [ -f filename ]'
b. Get file size with a combination of 'ls -l' and 'cut'
c. Sleep for a bit
d. Get file size again
e. Compare and loop if different otherwise action and move file

But surely there's a better way!
 
The best way should be the remote server to do a test of file transfer successful or not and then pass the result to your local server rather than running a endless loop to dominate your server cpu usage. If you can't control the remote one. Could the script run by an hour/day or not? Because I don't suggest you to do it for only one file status.

Just my suggestion

tikual
 
Tikual,

The files are being sent on an adhoc basis and I unfortuinately have no control over them or the remote server. The CPU usage is low (test server) so I don't mind this script running in the background as long as it sleeps between checking for a file's existence.
 
It seems to be your only way to do that. Then enhance your script efficiency. Can you post your script here? Just think that you may get the size by a smart way.

tikual
 
I think there have been previous threads to chack whether a file is in use (ie possibly being written to) using fuser. If fuser returns nothing, then presumably the file is complete.
 
Many thanks Ken, I've just experimented with fuser and it returns something when the file is being transferred - excellent! Now for a command better than 'ls -l' to get the file size (as a fail safe). 'sum' returns checksum, so maybe that'll do the trick - surprised there seems to be no specialised UNIX command to return a file's size.
 
Cheers for the star - a command like:

ls -la | grep <filename> | tr -s ' ' ' ' | cut -f5 -d ' '

will give you the size of the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top