4

Let's say we have machine 1 and machine 2.
Machine 2, which is linux based, is receiving a file (let's say cat.jpg sent via SCP from machine 1 (doesn't really matter which operating system..).

How can I know in machine 2, that the file has finished uploading from machine 1 ?
Please note that by "knowing" I mean by running a command (via a cron that runs every minute), and not by an event driven way ("make the scp issue a command when it is finished uploading").

Another limitation I have is that I can't change anything in machine 1 or in the way it SCP files.

If it really matters:

  • the files being transferred are video file, MP4 extension.
  • machine 2 is ubuntu 10.10
  • Check if the receiving process still exists. – mpez0 Jun 10 '11 at 18:31
4

you should be able to use the lsof command to check if the file is open in another program.

lsof | grep filename

if you get a result the file is open in another process and probably still uploading. If the result is blank the file is finished uploading or possibly the transfer failed for some reason.

| improve this answer | |
1

There may be a cleverer way of doing it, but in these situations I just use ls to show the file size and then wait for it to stop changing for a reasonable period of time (10-20 secs) -eg:

watch ls -l *.mp4
| improve this answer | |
  • This might be unsafe. E.g. if you replace the existing file with the same or larger size – Mitrakov Artem Aug 17 '19 at 12:48
1
fuser -mv / 2>&1 | grep F

That will list all users, pid and files open and in writing in a given mount-point.

| improve this answer | |
0

as root:

fuser filename

If something is printed out, then the file is currently used by some process.

| improve this answer | |
0

This works for me:

while [ true ]; do
    SAMPLE1=`ls -l --full-time $FILE`
    sleep 5
    SAMPLE2=`ls -l --full-time $FILE`
    if [ "$SAMPLE1" == "$SAMPLE2" ]; then
      echo done!
      break
    fi
done
| improve this answer | |
0

One way to rather safely assume that the scp command is over, is to list the files that have been modified more than 30s ago:

find /tmp/*mp4 -mmin +0.5

Now, you could decrease/increase the mtime value to make the file processing quicker/safer.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.