LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Linux SSH Server File status (https://www.linuxquestions.org/questions/linux-server-73/linux-ssh-server-file-status-4175496126/)

Kingsters 02-25-2014 04:49 AM

Linux SSH Server File status
 
I have a script to find a files in SSH server on every hour. The source files in ssh server which will comes from another server. My Script will have capability to check whether the files are available or not in particular directory.

How to find the file status?
Suppose the files are huge still copying status in source server. Gow to check the files are not fully copied in server?

Please help me on this..

TenTenths 02-25-2014 05:31 AM

You can use lsof /path/to/the/file to check if your file is in use by any other process, if it's not being used by a process like rsync/scp then you can assume it's fully copied.

Kingsters 02-25-2014 06:10 AM

thank you.. I will check it and let you know sson.

jpollard 02-25-2014 09:59 PM

It would be better to have the process sending the data put it in a different directory (same disk). That way even if the transfer of the file is interrupted (and thus either incomplete or corrupted) you wouldn't try to process it.

Once the file has arrived (and presumably verified/validated), use "mv" to put it in the directory
you will look for it.

Directory operations are atomic...

File transfer is not... and just because a process isn't currently using the file doesn't mean the file is complete...

Oh, and for processing the file - first move it out of the directory... You woudn't want to be in the middle of processing a file and have it change out from under you....

byau 02-28-2014 12:36 PM

If you don't mind a bit of extra scripting, you can run md5sum hash on remote side, copy those over first, then as your files are transferring md5sum hash on the local side and once they match, you know your files are done copying

Also a very good idea, because even if the file is done copying, you won't know if they are pristine copies until you run the md5sum hash anyway

Fresh in my mind, just wrote a blog post about this and why md5sum hash is a very valuable tool

http://geekswing.com/geek/the-magic-...sha-1-vintage/


All times are GMT -5. The time now is 12:02 PM.