Unix side-by-side difference with a remote hidden file

Viewed 195

I am working on a battery of automatic tests which executes on 2 Unix virtual machines running with KSH. Those VMs are independant and they have practically the same .profile file. I would like to study their differences by launching:

tkdiff /usr/system/.profile system@{external_IP}:/usr/system/.profile

on the first VM but it doesn't work.

enter image description here

I suppose that directly accessing a hidden file is not possible. Is there a solution to my problem, or maybe an alternative?

3 Answers

If you want to compare different files on two remote machines, I suggest the following procedure:

1. Compare checksums:

First compare the checksums. Use sum, md5sum or sha256sum to compute a hash of the file. If the hash is the same, the probability of having the same file is extremely high! You can even increase that probability by check the total amount of characters, lines and words, in the file using wc.

$ file="/usr/system/.profile"
$ md5sum "$file" && wc "$file"
$ ssh user@host "md5sum '$file' && wc '$file'"

2. run a simple diff

Run a simple diff using the classic command line tools. They understand the POSIX standard to use - as /dev/stdin. This way you can do:

$ ssh user@host "cat -- '$file'" | diff "$file" -

note: with old versions of tkdiff or new versions of svn/git, it can be tricky here due to bugs in tkdiff. It will quickly throw errors of the form svn [XXXX] file .... is not a working copy or file xxxx is not part of a revision control system if one of the files might be under version control or you end up in a directory under version control. Stick to diff!

You are using the filename convention "user@host:/path/to/file" for the second argument to tkdiff.

That convention for naming is not native to Ksh, but instead is understood by some programs like scp and others (which can be interactive, e.g. to ask for a password for the remote system or other authentication related questions).

But from the tkdiff man page, it does not mention having built-in support for that filenaming convention userid@host:/path/to/file, and neither is such support built into ksh.

So you may need to use two steps, first to use scp or similar to copy the remote file locally then then use tkdiff with one argument the local file and the other the file-just-copied, or arrange to mount part of the other VM filesystem locally, and then use tkdiff with appropriate arguments.

Obviously, both files need to be readable by your userid or the user specified on the userid@host:/path/to/file for this to work.

You can directly made a remote ssh compare , run a remote display with help of cat command line, with this :

tkdiff <(ssh system@{external_IP}1 'cat /usr/system/.profile') <(ssh system@{external_IP}2 'cat /usr/system/.profile')

In your case to be able to compare with the local .profile file this :

tkdiff /usr/system/.profile <(ssh system@{external_IP} 'cat /usr/system/.profile')

Do you have just try with the simple diff command line (with -b -B option to remove blank line and space comparaison):

diff -b -B /usr/system/.profile <(ssh system@{external_IP} 'cat /usr/system/.profile')
Related