简体   繁体   English

本地/远程服务器中相同文件上的不同 md5sum

[英]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.我想检查我在本地机器上的文件列表的 md5sum,并将其与我复制到远程服务器上的相同文件的 md5sum 进行比较。

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 :现在,如果我将这些命令运行到 bash 脚本中:

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.我在脚本中看到的唯一区别是,我对'*.fastq.gz'使用了简单的引号,而不是我之前的命令中的双引号。 But I have to or I get find: paths must precede expression error.但我必须或我得到find: paths must precede expression错误find: paths must precede expression

Why I don't have the same md5sum and how can I fix this ?为什么我没有相同的 md5sum,我该如何解决这个问题?

You're hitting a quoting problem: on the remote server section you need to scape the $ , like this: awk '{print \\$1}' :您遇到了引用问题:在远程服务器部分,您需要转义$ ,如下所示: awk '{print \\$1}'

Resulting:结果:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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