Compare files in 2 servers

I need to compare same set of files in 2 different servers and generate a list (in STDOUT) which contain all the files that have changed. I don't have permission to create any temp files or folders in either servers.

  • One option is to use ' if [ file1 -nt file2 ]'. But for this I need to move file1 to one server and compare there. I may not have permission to write. so that wont work.

Someone suggested using variables. Can we achieve this using variables?

#!/bin/bash

getmd5sum()
{
   ssh ${1} "md5sum ${file} | awk '{print $1}'"
}

for file in $(cat file_list); do
    [[ "$(getmd5sum ipaddr1)" != "$(getmd5sum ipaddr2)" ]] && echo ${file} >> file.different
done
1 Like