1

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

melony_r
  • 177
  • 1
  • 1
  • 8
  • Utilities like `md5sum`, `sha1sum`, `shasum`, etc. all have a checking option which causes them to return a status if the checksums read from a file don't match the actual files. Using these should be rather straightforward. – Hasturkun Aug 01 '21 at 12:39
  • @Hasturkun, this is true for Linux utils, Solaris `digest` for example do not have this option. – Romeo Ninov Aug 16 '21 at 09:27

1 Answers1

2

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)

Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
  • Thank you for your reply. However. I use sunOS(Sparc- Enterprise) and the command md5sum,sha1sum does not work. Please advise. I can see I can use cksum , digest command to fetch the checksum but unsure how do I compare if both the checksum are accurate through the script. – melony_r Aug 15 '21 at 11:59