melony_r
melony_r

Reputation: 177

How to validate file transfers(cp,scp command) in unix shell scripts by checksum or md5 command?

I have a unix shell script that creates and transfers files from one path to another ( either from same server or from another) Then there is transfer of files to this folder from either same or different server.

I'm unable to identify a method through which I could verify my file transfer md5 or checksum through a script.usually I take the checksum of the source and destination folders and match them manually.

Please advise

Upvotes: 1

Views: 2049

Answers (1)

Romeo Ninov
Romeo Ninov

Reputation: 7225

In your script you can insert line like this:

sha1sum <list of files> >files.sha1

to generate file with sha1 sums. Then you transfer all the files (including file with hashes) to the target place, for example:

scp /path/* user@host:localion

and then exec (via ssh for example) this to check the sha1 hash of files on target:

ssh user@host "cd location; sha1sum -c files.sha1"

This all is just example you should tune it for your environment

In Solaris you can use command:

digest -a sha1 location/* >/directory/hash1
scp /path/* user@host:localion
ssh user@host "cd location; digest -a sha1 *" >/directory/hash2
diff /directory/hash1 /directory/hash2

(the last command will compare hashes from local and remote sites)

Upvotes: 2

Related Questions