How can I tell if a file has finished copying?

Code junkies hangout here

Moderators: ChriThor, 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.
LXF regular
Posts: 842
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
Site admin
Posts: 9048
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 0 guests