I am uploading a file via sftp and just performing the safety test if the file is completely uploaded to the remote server. I am taking md5 hash of both(file in local and file in remote server) and matching them. If they match I conclude that the upload was successful. Here is the part of code from shell script.
ssh $REMOTE_MC 'digest -a md5 $TARGET_DIR/$filename' > $HOME_DIR/remote_hash_$datetag.txt local_hash=$(md5sum $HOME_DIR/$dump | cut -d' ' -f1) echo "local = $local_hash" cat $HOME_DIR/remote_hash_$datetag.txt remote_hash=$(cat $HOME_DIR/remote_hash_$datetag.txt) echo "remote = $remote_hash" output: local = cd8d77f0467754bc0c1c7ac3fb7f6184 dee4a8484f99c577fd70cb8fa01e5995 remote = dee4a8484f99c577fd70cb8fa01e5995
The problem I am facing is that,when i run the script, hashes differ but if I run the command
ssh $REMOTE_MC 'digest -a md5 $TARGET_DIR/$filename' > $HOME_DIR/remote_hash_$datetag.txt
out of the shell script, i get the same hash. What am i doing wrong in the script?
Things I tried:
ssh $REMOTE_MC 'digest -a md5 $TARGET_DIR/$filename >> $TARGET_DIR/remote.txt'
I redirected the output to a remote file instead of local file, the remote file contains the correct hash. But if i redirect it to local file, the hash mismatches.
Thanks in advance.