简体   繁体   中英

Different md5sum on same files in local / remote server

I would like to check the md5sum of a list of files I have on my local machine and compare it to the md5sum of the same files I copied on a remote server.

If I check separately in the terminal on each machine :

# local
find . -type f -name "*.fastq.gz" -exec md5sum {} + | awk '{print $1}' | sort | md5sum
> 5a58015f2abec5bb1ee3e6a003ec4beb  -

# remote
find . -type f -name "*.fastq.gz" -exec md5sum {} + | awk '{print $1}' | sort | md5sum
> 5a58015f2abec5bb1ee3e6a003ec4beb  -

Now, if I run these commands into a bash script :

path_local="path/to/data/"
server_remote="user@ip.adress"
path_remote="path/to/data/"

local_md5sum=$(find ${path_local} -type f -name "*.fastq.gz" -exec md5sum {} + | awk '{print $1}' | sort | md5sum)
echo "local_md5sum : ${local_md5sum}"
remote_md5sum=$(ssh ${server_remote} "find ${path_remote} -type f -name '*.fastq.gz' -exec md5sum {} + | awk '{print $1}' | sort | md5sum")
echo "remote_md5sum : ${remote_md5sum}"

> local_md5sum : 5a58015f2abec5bb1ee3e6a003ec4beb  -
> remote_md5sum : 4a32580085edf9e49e00c46920517dd1  -

The only difference I see in my script is that I use simple quotes for '*.fastq.gz' instead of double quotes in my previous command. But I have to or I get find: paths must precede expression error.

Why I don't have the same md5sum and how can I fix this ?

You're hitting a quoting problem: on the remote server section you need to scape the $ , like this: awk '{print \\$1}' :

Resulting:

remote_md5sum=$(ssh ${server_remote} "find ${path_remote} -type f -name '*.fastq.gz' -exec md5sum {} + | awk '{print \$1}' | sort | md5sum")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM