How can I tell if a file has finished copying?

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

How can I tell if a file has finished copying?

Postby MartyBartfast » Sat Aug 04, 2012 3:44 pm

Hi folks,

Ive got a file being copied onto a server (via ftp or scp), when it arrives I need to copy it onto somewhere else.

is there a neat/simple way for me to know for sure that the file has arrived in it's entirity before I try and copy it on?

I could do md5sum $file; sleep 2s ; md5sum $file and compare the two sums to know that it's not still being written but that seems a bit messy to me.

Any other thoughts?
I have been touched by his noodly appendage.
User avatar
MartyBartfast
LXF regular
 
Posts: 814
Joined: Mon Aug 22, 2005 7:25 am
Location: Hants, UK

Postby nelz » Sat Aug 04, 2012 6:05 pm

lsof will tell you if the copy process still has a lock on the file. Or you could use the wait command to check when the process has completed.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8469
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests