LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-07-2012, 06:35 PM   #1
unix_72427
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Rep: Reputation: Disabled
Smile Shell Script to compare folders,Sub-Folders and Sub-Sub-Folders


Dear All,

I am trying to built a shell script which will compare all the folders like directories,sub-dir and sub-sub-Dir between two servers.

Can it be possible ?

If yes, Could you please give some idea which will help me a lot .

Thanks.
 
Old 08-07-2012, 06:56 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,330

Rep: Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089
Quote:
Originally Posted by unix_72427 View Post
Dear All,

I am trying to built a shell script which will compare all the folders like directories,sub-dir and sub-sub-Dir between two servers.

Can it be possible ?

If yes, Could you please give some idea which will help me a lot .

Thanks.
very possible. I suggest you look up some of the bash scripting tutorials you can find on google.

what are you trying to accomplish? It could be that you could use rsync for another utility to do what you want to do.
 
Old 08-07-2012, 07:29 PM   #3
unix_72427
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
very possible. I suggest you look up some of the bash scripting tutorials you can find on google.

what are you trying to accomplish? It could be that you could use rsync for another utility to do what you want to do.
Hi,

Thanks for your quick response,

i want to compare files from two servers folders ,sub-folders,sub-sub-folders and so on ...

i searched through out the forum but i am not getting any satisfactory answer .

Need your help to achieve the above .

Thanks.
 
Old 08-08-2012, 03:00 AM   #4
jimtony
Member
 
Registered: Jan 2011
Location: Shanghai,China
Distribution: fedora
Posts: 73
Blog Entries: 1

Rep: Reputation: 2
diff command will show two directory's difference.
[root@~]diff dir1 dir2
 
Old 08-08-2012, 10:01 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,330

Rep: Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089
Quote:
Originally Posted by unix_72427 View Post
Hi,
Thanks for your quick response,

i want to compare files from two servers folders ,sub-folders,sub-sub-folders and so on ... i searched through out the forum but i am not getting any satisfactory answer .
Ok, so again, post what you've written, and what you're trying to accomplish, and we can try to help. But, we are NOT going to write your scripts for you. There are many bash scripting guides you can find with a VERY easy Google search, like this:

http://tldp.org/LDP/abs/html/

The diff command can do some parts of what you want, but again, you're not telling us what your goal is. If this is homework, post where you're stuck. If it's for a production environment, there are other tools you can use to do this.
 
Old 08-08-2012, 11:32 AM   #6
unix_72427
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Ok, so again, post what you've written, and what you're trying to accomplish, and we can try to help. But, we are NOT going to write your scripts for you. There are many bash scripting guides you can find with a VERY easy Google search, like this:

http://tldp.org/LDP/abs/html/

The diff command can do some parts of what you want, but again, you're not telling us what your goal is. If this is homework, post where you're stuck. If it's for a production environment, there are other tools you can use to do this.
Hi,

Am trying to achieve like

for Example.

Code:
 

Serv 1
========
/admin
       A
          X
          Y
       B
          Z
          W
       C
/properties
       1
          4
          5
          7
       12
          d
          e
/super
       22
========
Serv 2
========
/admin
       A
          X
          Y
          O
       B
          Z
          W
       C
/properties
       1
          4
          5
       12
          d
          e

=============
O/P
-------------
Serv1                                  Serv2
----------------------------------------------
/admin/A/                          1.)/
-------                             ------------
missing folder O                   missing /super folder

                                   2.)/properties/1
                                    ----------
                                   missing folder 7
I gathered all the directories from both the servers in text file and am trying to put them in some loop like reading each line .
Code:
line=$1

while read LINE
do
      grep the line in both the file and spool into a file.

done < $line
Here am not sure will work or not . will glad if you give some input .

Last edited by unix_72427; 08-08-2012 at 11:56 AM.
 
Old 08-08-2012, 11:53 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,330

Rep: Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089
Quote:
Originally Posted by unix_72427 View Post
Hi,
Am trying to achieve like for Example.
Right...we understand what you're trying to do, and have since your first post. What we are asking for is
  • The code that YOU have written to do this
  • You to tell us where you're stuck or what problem(s) you're having
  • What your GOAL is..for example, is this to verify a backup, sync two servers over a WAN...what???
What effort have you put into solving this problem? Is this homework?? Just asking the same question over and over, without answering anyone elses questions won't get you much help....
 
Old 08-08-2012, 12:01 PM   #8
unix_72427
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Right...we understand what you're trying to do, and have since your first post. What we are asking for is
  • The code that YOU have written to do this
  • You to tell us where you're stuck or what problem(s) you're having
  • What your GOAL is..for example, is this to verify a backup, sync two servers over a WAN...what???
What effort have you put into solving this problem? Is this homework?? Just asking the same question over and over, without answering anyone elses questions won't get you much help....
This is not a homework. am trying in production environment to compare two servers and manually fill the gap.
 
Old 08-08-2012, 03:51 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,330

Rep: Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089Reputation: 8089
Quote:
Originally Posted by unix_72427 View Post
This is not a homework. am trying in production environment to compare two servers and manually fill the gap.
Ok...and how about the other parts of what we've been asking you???
  • The code that YOU have written to do this
  • You to tell us where you're stuck or what problem(s) you're having
  • What effort have you put into solving this problem?
If you're trying to keep two production servers in sync, use rsync, which was suggested to you in the very first reply. Have you looked up the command, and how it's used? This is what it was written for, and (since you say this is not homework), you should be able to use any utility you'd like.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script Compare Folders corteplaneta Programming 8 09-18-2010 02:32 AM
bash script to create folders including making recursive folders.... linux-bandit Linux - Software 8 11-28-2009 02:50 AM
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 05:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration