Question

There is a similar question: compare files in two directory on remote server using unix

But my situation is I can not login the remote server, it's customer machine, so can not use rsync, but I can request customer to export the directory structure, tell me the dir/file's name, size, md5 value etc.

I only want to display the file name that in different content.

How to do it? best using ksh...

Thanks in advance.

Was it helpful?

Solution

It kind of depends whether file dates and times are important or file contents...

If the dates are important (e.g. it's a syncing thing you are investigating) I would be running find with ls -l.

If the contents are important, I would want to be checking MD5 checksums like this:

find . -type f -print -exec md5 -q {} \;   > somefile

That gives output like this:

./West Wales 14-Oct-09.axe
2c0c390bfc4206b8b88e11d537eacda8
./wl
44f84a91a98da15381a198e29417170c
./YOURFILE
ea102bc16e2b449e4ac6770b73cb9c50
./YOURFILE.BAK
a6ba1946cb666cb3b88ac31e6fb3f3f0
./z.html
b4554a1044abe07fd23d4580dd3055cc

Then on your local machine, read the file and calculate its checksum locally and compare that with the remote one:

#!/bin/bash
while read fname
do
    read remotemd5
    localmd5=$(md5 -q "$fname")
    if [ $remotemd5 != $localmd5 ]; then
       echo $fname $localmd5 $remotemd5 
    fi
done < file

OTHER TIPS

Ask the customer to run a command to get all the relevant info, eg:

find . -type f -exec ls -l {} \; | sort > remote_dir.txt

Then run the same command locally:

find . -type f -exec ls -l {} \; | sort > local_dir.txt

Then you can use comm to compare the two and see what has changed.

comm -3 remote_dir.txt local_dir.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top