【问题标题】:Different md5sum on same files in local / remote server本地/远程服务器中相同文件的不同 md5sum
【发布时间】:2020-05-21 14:01:09
【问题描述】:

我想检查我在本地计算机上的文件列表的 md5sum,并将其与我在远程服务器上复制的相同文件的 md5sum 进行比较。

如果我在每台机器上的终端分别检查:

# 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  -

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

我在脚本中看到的唯一区别是我在前面的命令中使用了'*.fastq.gz' 的简单引号,而不是双引号。但我必须这样做,否则我会收到 find: paths must precede expression 错误。

为什么我没有相同的 md5sum,我该如何解决这个问题?

【问题讨论】:

  • 你为什么md5sum | md5sum???
  • 因为我有 26 个文件,第一个 md5sum 我得到一个 26 个 md5sum 的列表,然后我对这个列表进行排序,然后我对这个列表进行另一个 md5sum,这样我就可以只比较一个哈希值。我在这里找到它:stackoverflow.com/questions/1657232/…
  • 所以先比​​较所有(26行)输出!
  • 不幸的是,我们没有办法尝试这个!所以我们看不到bug在哪里...关心ssh ... "...'...$1...'..."尝试转义$符号或反转引号和双引号。
  • 或使用语法:ssh remote /bin/bash <<-"eosshcmd" ... 将脚本分成几行并在末尾添加eosshcmd... 确保使用引号中的单词,以免在命令中扩展变量。

标签: linux ssh server md5sum


【解决方案1】:

您遇到了引用问题:在远程服务器部分,您需要转义 $,如下所示:awk '{print \$1}'

结果:

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

【讨论】:

    猜你喜欢
    • 2014-11-24
    • 1970-01-01
    • 2020-08-27
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    相关资源
    最近更新 更多