1834533 Members
2805 Online
110069 Solutions
New Discussion

Re: Move file

 
nash11
Frequent Advisor

Move file

I have two hosts ( host A & host B ), they are in different locations , there are many files will be exchange among them , from time to time , some files are moved from host A to host B , and some files are moved from host B to host A , two hosts are connected via leased line , sometimes the leased line is not stable that the connection is broken , so the file exchange job may be fail , if I would like to make sure the file exchange is successful , can advise what is the best way ? if tar the files before move and check the file size in both server , is the possible , can advise how to do it ? thx
8 REPLIES 8
Ninad_1
Honored Contributor

Re: Move file

You can use cksum to verify the checksum of the file on both the machines. This is the most authentic way to find out if the files have been copied correctly and checksums match.

Regards,
Ninad
nash11
Frequent Advisor

Re: Move file

thx reply and suggestion ,

can advise how to use cksum , is it easy to implement ? thx
Torsten.
Acclaimed Contributor

Re: Move file

The cksum command is available by default.
See "man cksum" for more info.
You may run the command "cksum file" before and after the transfer and compare the results to ensure the file is ok.
You probably can automate this with a script.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
nash11
Frequent Advisor

Re: Move file

thx reply ,
I know cksum is used for checking the size of the file by byte , that's good but seems too low level . I just want to make sure the file is moved to remote site correctly , eg. if the leased line is broken then stop to move file until the line is resumed etc. thx
Peter Nikitka
Honored Contributor

Re: Move file

Hi,

cksum isn't too low level - you need to know if the transmission from A to B was completely and errorfree, so how should a check work without looking hard at the files?

I would tar+gzip the files to send, so the un-tar and gunzip can act as additional error checkers.
My example assumes ssh/scp connection, but can be adopted to other remote commands easily:
#!/usr/bin/sh
tar cf - files and dirs to send | gzip >toremote.tar.gz
cksum toremote.tar.gz >toremote.cksum
if scp toremote.tar.gz hostB:/todir
then :
else
print -u2 ERROR: file transfer failed
exit 1
fi

ssh hostB cksum /todir/toremote.tar.gz >fromremote.cksum

if cmp fromremote.cksum toremote.cksum
then ssh hostB 'cd wherever && gunzip else
print -u2 "ERROR: hostB:/todir/toremote.tar.gz is corrupted"
exit 2
fi


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Arunvijai_4
Honored Contributor

Re: Move file

Hi Nash,

You can also use "md5sum".

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
IT_2007
Honored Contributor

Re: Move file

you can implement rsync to copy files between two servers. This would be useful for automation and will sync only for changed files to copy. You can download and install it on both servers.
yhm_1
New Member

Re: Move file

you can create a sum file for the .tar
e.g : sum file.tar > file.tar.sum
after you finish to copy the file you can run sum on the file.tar : sum file.tar
on target and see if it's equal to the file.tar.sum