1

I am in need of creating and checking checksums between a local file, and the remote file I just pushed. If the MD5 checks, continue, else break. This needs to be in KORN shell scripting because we are using AIX machines.

here's the code I have so far:

for file in <<Directory>>; do
    -- Get MD5 of local file
    LOCALMD5=!chsum "$(basename "$file")"
    sftp <<USER>>@<<IP>> <<EOF
    PUT file <<SFTP OUTPUT FOLDER>>
    REMOTEMD5= <<<COMMAND HERE>>>>  <<--- Which command?
    IF [[LOCALMD5!=REMOTEMD5]]; THEN
        RETURNVALUE = -1
        BREAK
done

print RETURNVALUE

How do I get the remote MD5 checksum?

  • Are you actually calling cksum, or is chsum some other local utility/function/wrapper? – Jeff Schaller Oct 10 '18 at 20:27
  • this is new code, so we are using cksum right now. – arcee123 Oct 10 '18 at 20:28
  • New to Korn Scripting – arcee123 Oct 10 '18 at 20:28
  • do you have csum available? (AIX 7's supports MD5) – Jeff Schaller Oct 10 '18 at 20:35
  • do you have ksh93 available? (for array support) – Jeff Schaller Oct 10 '18 at 20:36
1

Since you say: the remote file I just pushed, the probability of any file difference is extremely low over sftp (based on ssh code). As low as (in the order of) the probability that the md5 of two different files have the same hashsum.

And, the short answer is:

An sftp session doesn't allow remote execution of commands. So, if you cannot ssh to the machine, you don't have a way to remotely run md5.

So, to check a remote file you will need to read it back, which, IMhO seems silly.


The only way is, then, to do:

ssh user@remote-dns-name 

And once in the shell it opens, execute the command(s) you need:

$ cd path/to/file
$ csum -h MD5 >MD5-hashsum-filename

And then, copy the file created back to the local machine.

  • Thanks much. guess that's the way I have to go. – arcee123 Oct 11 '18 at 2:59

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.