Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Linux / UNIX and the fly likes need script to compare directories in two different servers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "need script to compare directories in two different servers" Watch "need script to compare directories in two different servers" New topic
Author

need script to compare directories in two different servers

Chandrasekaran SanthanaKrishnan
Greenhorn

Joined: Mar 29, 2011
Posts: 7
I have a requirement.
I need to write a shell script which will compare two directories residing in two different servers (SERVER A and SERVER B) and list out the discrepancies if found any.

directory structure is different in both the servers
say

dir structure in Server A - /home/dir/dir2
dir structure in Server B - /office/folder/subfolder/subsubfolder

Script will be working in SERVER A.


Please help.

Server A is Solaris OS.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

The hardest part is getting local file access to both directory trees. If you have NFS on the Solaris machine, you can export the Solaris share to the Linux machine and run the compare on the Linux machine (or vice versa, if you prefer).

To compare directories in general, I do this:



The "q" option limits the output to just the names of the files instead of details and the "-x .svn" is because I don't want it comparing my Subversion work directories, since they're not important here.


Customer surveys are for companies who didn't pay proper attention to begin with.
Chandrasekaran SanthanaKrishnan
Greenhorn

Joined: Mar 29, 2011
Posts: 7
Thanks Tim.

I tried that diff for local directories.

Problem is dir B is in remote host.

I do not know if i can do NFS. If so how to do that?

is there any other way without NFS?
Sanjeev Ba
Ranch Hand

Joined: Dec 31, 2006
Posts: 40

I agree with Tim in that getting the network bit right is the key.

There are multiple options here.
1. ftp - you might be able to install ftp service with user permissions.
a. set up ftp on one machine and get the recursive directory listing from another machine using sftp.
2. If you have admin rights, check out NFS way
You need to install nfs server, edit /etc/exports file and start the server.
Then mount the remote folder in A to to a local folder in machine B and compare.
3. if you have access to the web interface of this machine and if it is possible to expose the folder structure via the web interface you could you wget
4. setup rsync between remote and local server.

Any of these will work depending on the permission levels you have on these machines.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need script to compare directories in two different servers
 
Similar Threads
Question 66 of Quiz B of MasterExam of K & B
I want my ant script Implement a function
Jboss: multiple instances, passing java properties, different ports
How to export CLASSPATH variable?
About encodeRedirectURL