Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
12-07-2007, 04:07 AM
|
#1
|
Member
Registered: Oct 2005
Location: Bangladesh
Posts: 504
Rep:
|
Compare folder/files from remote server
Friends ,
Suppose I have two same folders in machine A (Linux) and in machine B (Linux) . Now I am compare these two files using "diff" command .
I mean running diff command in following way :
diff folder1 (machine A) folder2 (machine B)
Can I do it ?
Plz help .. ...
|
|
|
12-07-2007, 04:37 AM
|
#2
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
You said file and folder. Which do you mean?
Diff compares the contents of two files. It does not (directly) compare directories.
Diff compares files only - not URLs. When you say remote, what do you mean? If the remote files are mounted on the local system using NFS or SMB or something else which allows you to see them in the local filesystem this is fine, but if you access the files using HTTP or FTP, this is a little more complicated.
|
|
|
12-07-2007, 04:53 AM
|
#3
|
Member
Registered: Oct 2005
Location: Bangladesh
Posts: 504
Original Poster
Rep:
|
diff command in remotely
Thx matthewg42 .
Acyually I have a file called "file1" in Linux A .
In Linux B i have same file caled 'file2'
Now i need to run diff command in a shell script .
But I cannot go to the file2 in LinixB easily . So that I need ur help how can I comapre this two files where files are in different machines ......
Waiting ur kind reply .. ...
|
|
|
12-07-2007, 05:14 AM
|
#4
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
Some more questions: - Do you have the ability to ssh from A to B?
- What sort of results are you looking for - do you want to know just if the files are different, or do you want to know what the differences are?
- If you want to know what the differences are, is normal diff output what you want?
- Are the files big and the network slow (i.e. is it practical to copy the file from B to A?)
|
|
|
12-07-2007, 05:20 AM
|
#5
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
You can compare files remotely using ssh like this
Code:
ssh <remote-host> "cat /path/to/remotefile" | diff - /path/to/localfile
where <remote-host> is the address of the remote machine. This will execute "cat /path/to/remotefile" on the remote host and will compare it with /path/to/localfile. The command
Code:
diff - /path/to/localfile
means compare standard input with the content of /path/to/localfile. The standard input is passed through the pipe.
Maybe you have to elaborate to suite to your needs. For example, you may want to generate private/public ssh keys to avoid prompting for password. Also if you want to compare files with blank space in their name you have to escape it, e.g.
Code:
ssh <remote-host> "cat remote\ file" | diff - local\ file
I hope this will help.
|
|
|
12-07-2007, 05:43 AM
|
#6
|
Member
Registered: Oct 2005
Location: Bangladesh
Posts: 504
Original Poster
Rep:
|
diff in remoter server
sorry colucix ,
ssh is not directly connected to the remote server without password , is it ?
It shows follwoign error :
[root@server ~]# ssh 192.168.101.129 "cat /tmp/file2" | diff - /root/file1
diff: cannot compare `-' to a directory
connect to address 192.168.101.129: Connection refused
Trying krb4 ssh...
connect to address 192.168.101.129: Connection refused
trying normal ssh (/usr/bin/ssh)
sshd: 0826-826 The host name for your address is not known.
|
|
|
12-07-2007, 06:34 AM
|
#7
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by shipon_97
ssh is not directly connected to the remote server without password , is it ?
|
No, of course. You have to setup public key authentication for passwordless connection. See man ssh and man ssh-keygen for details.
Quote:
[root@server ~]# ssh 192.168.101.129 "cat /tmp/file2" | diff - /root/file1
diff: cannot compare `-' to a directory
connect to address 192.168.101.129: Connection refused
Trying krb4 ssh...
connect to address 192.168.101.129: Connection refused
trying normal ssh (/usr/bin/ssh)
sshd: 0826-826 The host name for your address is not known.
|
This means two things: first, /root/file1 on the local machine is a directory, not a file, isn't it? So it would be more tricky to compare directories by this method. Second, it looks like the remote machine does not resolve the host name of your local machine and refuse connection. Try to investigate this problem before proceeding.
|
|
|
12-07-2007, 06:41 AM
|
#8
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
Here's how to configure ssh to work using public key authentication (which you can use to do remote commands without being prompted for a password each time):
http://sial.org/howto/openssh/publickey-auth/
|
|
|
01-22-2010, 08:09 AM
|
#9
|
LQ Newbie
Registered: Jan 2010
Posts: 2
Rep:
|
Quote:
Originally Posted by colucix
No, of course. You have to setup public key authentication for passwordless connection. See man ssh and man ssh-keygen for details.
This means two things: first, /root/file1 on the local machine is a directory, not a file, isn't it? So it would be more tricky to compare directories by this method. Second, it looks like the remote machine does not resolve the host name of your local machine and refuse connection. Try to investigate this problem before proceeding.
|
Hi all, I know this thread is quite old, but I am facing a similar issue now...what I need to know is "it is possible to combine cat , diff and ssh to compare the content of two directories ( and so recursively of all the files into them ) located on two different machines?
|
|
|
01-24-2010, 05:56 PM
|
#10
|
LQ Newbie
Registered: Sep 2009
Location: Slovakia
Distribution: Trisquel 5.0 Dagda
Posts: 27
Rep:
|
I only can imagine the following:
ssh your@connection find ./folder -type f -exec cat \;>> ./freespace; find ./folder -type f -exec cat \; >> ./evenmorespace; diff ./freespace ./evenmorespace
Last edited by White Tea Citrus; 01-24-2010 at 05:59 PM.
|
|
|
01-24-2010, 06:58 PM
|
#11
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Or use sshfs to mount the remote directory through ssh (it requires FUSE) and then just diff recursively. Here is a quick and dirty example (suppose you have to compare /path/to/local/dir and /path/to/remote/dir)
Code:
$ mkdir local-mount-point
$ sshfs user@host:/path/to/remote/dir local-mount-point
$ diff -r /path/to/local/dir local-mount-point
<omitted results of comparison>
$ fusermount -u local-mount-point # to unmount
The only glitch is that on many systems the fusermount command has the setuid attribute set and you can run it only by gaining root privileges. A common workaround is to add yourself (or ask the system administrator to add you) to the fuse group.
|
|
1 members found this post helpful.
|
01-26-2010, 06:55 AM
|
#12
|
LQ Newbie
Registered: Jan 2010
Posts: 2
Rep:
|
Quote:
Originally Posted by colucix
Or use sshfs to mount the remote directory through ssh (it requires FUSE) and then just diff recursively. Here is a quick and dirty example (suppose you have to compare /path/to/local/dir and /path/to/remote/dir)
Code:
$ mkdir local-mount-point
$ sshfs user@host:/path/to/remote/dir local-mount-point
$ diff -r /path/to/local/dir local-mount-point
<omitted results of comparison>
$ fusermount -u local-mount-point # to unmount
The only glitch is that on many systems the fusermount command has the setuid attribute set and you can run it only by gaining root privileges. A common workaround is to add yourself (or ask the system administrator to add you) to the fuse group.
|
Thanks a lot, I liked this solution and it worked!
|
|
|
01-26-2010, 01:04 PM
|
#13
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by lela2416
Thanks a lot, I liked this solution and it worked!
|
You're welcome!
|
|
|
All times are GMT -5. The time now is 07:21 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|