Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to Compare two directories

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
0
0
ZA
I have the following script which is to compare two directories using the sdiff command
Code:
 #!/bin/ksh

LOCALFOLDER=/u1/mac2
REMOTEFOLDER=$(rsh sun5 'ls -lA /u1/mac2' > remotessh.txt)
COMMAND=$(ls -lA $LOCALFOLDER > localssh.txt)
REM=$(cat remotessh.txt)
LOCAL=$(cat localssh.txt)

echo $LOCAL
echo $REM

if [ $REM -eq $LOCAL ]
 then
      echo Directories are the same
 else
      echo Directories are differnt
 fi

#sdiff localssh.txt remotessh.txt | grep '\|'

The output files were created from local and remote servers, I need to put the differences into another file and email the differences how will I do that?

I would also like to cut from the files created the permissions etc, how can i do that?
herewith output file
Code:
drwxrwxr-x   3 mac2     querix         3 Nov 30 00:00 .sunstudio
drwx------   3 mac2     querix         3 Nov 30 00:00 .sunw
drwxr-xr-x   3 mac2     querix         3 Nov 30 00:00 .vim
-rw-rw-r--   1 mac2     querix      6197 Nov 30 00:00 .viminfo
-rw-rw-r--   1 mac2     querix       102 Nov 30 00:00 .vimrc
-rw-------   1 mac2     querix       200 Nov 30 00:00 .Xauthority
-rwxrwxr-x   1 mac2     querix     46352 Nov 30 00:00 a_calc00.4ge
-rw-rw-r--   1 mac2     querix     11902 Nov 30 00:00 a_calc00.4gl
-rw-rw-r--   1 mac2     querix        60 Nov 30 00:00 a_calc00.def
-rw-rw-r--   1 mac2     querix      1527 Nov 30 00:00 a_calc01.per
-rw-rw-r--   1 mac2     querix      1464 Nov 30 00:00 a_calc01.pic
-rwxrwxr-x   1 mac2     querix     66208 Nov 30 00:00 a_ecb000.4ge
-rw-rw-r--   1 mac2     querix     24895 Nov 30 00:00 a_ecb000.4gl
-rw-rw-r--   1 mac2     querix       112 Nov 30 00:00 a_ecb000.def
-rw-rw-r--   1 mac2     querix       444 Nov 30 00:00 a_ecb000.per
-rw-rw-r--   1 mac2     querix       322 Nov 30 00:00 a_ecb000.pic
-rw-rw-r--   1 mac2     querix      1929 Nov 30 00:00 a_ecb001.per
-rw-rw-r--   1 mac2     querix      2357 Nov 30 00:00 a_ecb001.pic
 
To keep the first column of "myfile.txt", type:

Code:
awk '{print $1}' myfile.txt
 
Would you not be better off checking checksum/MD5 Sum's of the files within directories on each of the specific nodes building a sorted listing then fetch the lists from each node and diff them against the master node, producing a report for each?

Or is that a bit too low-level for your needs?

Or you could utilize something like Tripwire that does that and more for you ;)


Laurie.
 
Thanks,

I got the Awk working.BUT i have sub-directories within the directory that i would also like to check.
I changed my script to do a "ls -lAR" to include files from all subdirectories.

MY txt file displaying all differences is much bigger, but not showing me in which directory the differences are
How can i change my script to list the directories and the files within that sub-directories.
 
Instead of using ls -lAR try using find /u1/mac2 | xargs ls -ld, that way it should include the full path with every filename.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top