I am running my below shell script on machineC which gets the md5sum of my files in my PRIMARY directory in machineC itself.#!/bin/bashexport PRIMARY=/data01/primaryfor entry in $PRIMARY/*do    local_md5sum=$(/usr/bin/md5sum $entry | awk '{print $1}')    echo $local_md5sumdoneAs soon as I run above shell script then it prints out the md5sum of my files in machineC and it is working fine.Now same file for which I am calculating the md5sum can be either in machineA or machineB as well so I need to do ssh on machineA and machineB and do the same md5sum on the same file and store it in remote_md5sum variable.If the file is not there in machineA, then it should be there in machineB for sure and the files will be in this directory in machineA and machineB/bat/test/data/snapshot/20140918So I got below shell script which I am running on machineC and is also trying to find the md5sum of the files on machineA or machineB#!/bin/bash# folder in machineCexport PRIMARY=/data01/primaryreadonly SERVERS=(machineA machineB)export SERVERS_1=${SERVERS[0]}export SERVERS_2=${SERVERS[1]}export FILES_LOCATION=/bat/test/data/snapshot/20140918  for entry in $PRIMARY/*do    # find local md5sum on machineC    local_md5sum=$(/usr/bin/md5sum $entry | awk '{print $1}')    echo $local_md5sum    # find remote md5sum of the file which will be on machineA or machineB    remote_md5sum=$(ssh user@$SERVERS_1 /usr/bin/md5sum $entry | awk '{print $1}' || ssh bullseye@$SERVERS_2 /usr/bin/md5sum $entry | awk '{print $1}')    echo Remote Checksum: $remote_md5sum    # now compare local_md5sum and remote_md5sumdoneBut whenever I run above shell script my ssh command fails and it doesn't store md5sum value of that file in remote_md5sum. Is there anything wrong in this syntax?remote_md5sum=$(ssh user@$SERVERS_1 /usr/bin/md5sum $entry | awk '{print $1}' || ssh user@$SERVERS_2 /usr/bin/md5sum $entry | awk '{print $1}')
How to find md5sum of files on remote machines by doing ssh?
bash;shell;ssh;hashsum
I have modified your script and this one works now. I have added some comments inside the script to make it more understandable. Let me know if you need more help. #!/bin/bash#The export path which we set here.export PRIMARY=/home/ramesh#The main for loop execution starts here. for entry in $PRIMARY/*do    #Get the base name of the file which we check in the remote servers.    #Get just the filenames without the path.    #I am going to use the filename in the remote server to check.     filename=$(basename $entry)    echo File Name: $filename    #Calculate the MD5Sum locally.    local_md5sum=$(md5sum $entry)    echo Local MD5Sum: $local_md5sum    #Check if the file exists in server1.     #Otherwise I can check in the other server.    if ssh ramesh@server1 stat /home/ramesh/'$filename' \> /dev/null 2\>\&1 then        #I have the file in server1 and so I get the md5sum from server1.        #I store the md5sum inside remote_md5sum variable.        remote_md5sum=$(ssh ramesh@server1 cd /home/ramesh/; find -name '$filename'  -exec md5sum {} \;)    else        #Now, I know the file is in server2 as it is not present in server1.         remote_file=$(ssh ramesh@server2 cd /home/ramesh/; find -name '$filename'  -exec md5sum {} \;)    fi    echo Remote MD5Sum: $remote_filedoneTestingI wanted to test the above script for file names with spaces as well. It works well and this is the output that I get when I execute the script.File Name: file1Local MD5Sum:  39eb72b3e8e174ed20fe66bffdc9944e  /home/ramesh/file1Remote MD5Sum: b5fc751f836c5430b617bf90a8c4725d  ./file1File Name: file with spacesLocal MD5Sum:  36707e275264f4ac25254e2bbe5ef041  /home/ramesh/file with spacesRemote MD5Sum: 36707e275264f4ac25254e2bbe5ef041  ./file with spaces