Elysire
Elysire

Reputation: 713

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="[email protected]"
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 ?

Upvotes: 1

Views: 660

Answers (1)

Juan P. Osio
Juan P. Osio

Reputation: 475

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")

Upvotes: 1

Related Questions