Thursday, January 22, 2009

Diff remote files using ssh in Linux


I have already discussed how we can edit a remote file using vi and scp in one of my previous post ; today we will see how we can find or show differences between a local file and a remote file using ssh.

Suppose we have to find the differences between local file "/tmp/filepurge.sh.old" and remote file "/root/scripts/filepurge.sh" located in remote host 172.21.16.11.

This is how can do it:

$ ssh root@172.21.16.11 "cat ~/scripts/filepurge.sh" | diff - /tmp/filepurge.sh.old

And using vimdiff:

$ vimdiff scp://root@172.21.16.11//root/scripts/filepurge.sh /tmp/filepurge.sh.old

** We would need ssh to work using public key authentication so that we can do remote commands execution without being prompted for passwords.

3 comments:

David Milam said...

Thank you! That tip came in very handy today.

awkseeker said...

Hi Jadu,
I have few experienced with ssh from linux to unix. I want to know if I would do same from linux to windows, for example I want to send command to windows (dir, ipconfig, del, ren ...)

Sincerely

awkseeker said...

Could I do same from linux to Windows, such as send command del, ipconfig, ren ...

© Jadu Saikia www.UNIXCL.com