1

I'm writing a script. The idea is to compare MD5 checksums between a local file and a remote one.

The local file checksum is saved into a local variable:

LOCALMD5=!chsum "$(basename "$file")"

I was just recommended this script to get the md5 checksum on the remote file. do:

ssh user@remote-dns-name 
cd path/to/file
csum -h MD5 >MD5-hashsum-filename

Assuming I can successfully run csum in an ssh environment, how do I set the output of that command back to a local variable that I can use into the future?

  • since you're comparing checksums, I think it'd make more sense to ssh user@remote "cd /path; csum ..." > /path/to/local/file; and then csum -i /path/to/local/file. – Jeff Schaller Oct 11 '18 at 13:14
  • Thanks Jeff. This is a bit confusing for me here. how do I actually perform the check in the script? – arcee123 Oct 11 '18 at 13:21
  • I'm considering writing up an answer to your previous question, though you seem to have accepted an intermediate answer already. – Jeff Schaller Oct 11 '18 at 13:23
  • well, you did answer it. I'm generating questions as the situation pops up. Besides, you get more points. :) – arcee123 Oct 11 '18 at 13:24
  • well, I thought it was you. – arcee123 Oct 11 '18 at 13:24
1

You should be able to just capture the STDOUT of csum through ssh.

To get the full output of csum, with both the hash and the filename:

bash-$ remoteMD5=$(ssh user@remote-dns-name "csum -h MD5 /full/path/to/file")
bash-$ echo $remoteMD5
723fc34e606a4d0002fe86f417be5f56 /full/path/to/file

Or you could return just the hash:

bash-$ remoteMD5=$(ssh user@remote-dns-name "csum -h MD5 /full/path/to/file" | awk '{print \$1}'")
bash-$ echo $remoteMD5
723fc34e606a4d0002fe86f417be5f56

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.