Need a shell script to compare two directories and produces the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a shell script to compare two directories and produces the output
# 8  
Old 03-28-2012
MySQL

Hi Thanks for the response.

@suhasingale:yeah that's correct but problem is we cannot connect to the other server because it is in different network.
what is my plan is develop a script and execute it first our envrionment and will send the script to the other server owner and ask them to send the out put file after running the same script.from there will compare two files outputs.

@rangarasan: Can we get the count also at the end to get an idea of the how many files are present in the perticular directory.
# 9  
Old 03-28-2012
ok - I understand now. You will have to write a script to compare two file in two ways then.
# 10  
Old 03-28-2012
bash

Yes, You can Smilie

Try this one,

Code:
#! /usr/bin/bash
if [ $# -ne 2 ];then
echo "Usage: $0 [location] [outputfile]";
exit;
fi
dir=$1
output=$2
filecnt=0
dircnt=0
cd $dir
rm $output
for i in `find $dir -name "*"`
do
    if [ -d "$i" ];
    then
        echo "DIR:$i" >>$output
        let dircnt++
        continue
    fi
    echo $i >>$output
    let filecnt++
done
echo "File Count:$filecnt" >>$output
echo "Directory Count:$dircnt" >>$output

Cheers,
RangaSmilie
This User Gave Thanks to rangarasan For This Post:
# 11  
Old 03-28-2012
Hi.

If your system has rsync, I'd use that in the dry-run mode. That would tell what would need to be changed to put the directories in sync. That may or may not be a sufficient report for your purposes, but it would be relatively easy to do (although there is a myriad of available options for rsync) , and could be used as a source for comparison if you had to write a script.

Ir was not installed by default on one Solaris 10 (386) system that I use, but it was on an OpenIndiana box.

Otherwise, it seems to me that you'd need to send data back in a kind of skeleton form, which would describe the directory structure, along with a checksum of the files, and do the compare based on the checksums calculated for the local files ... cheers, drl

Last edited by drl; 03-28-2012 at 10:23 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk runs and produces output but with error

When I run the awk below, I get an error message awk -v OFS='\t' '$(NF-1)=="Benign" || ($(NF-2) OFS $(NF-1))=="Likely Benign" {$(NF)=$(NF-2) OFS $(NF-1)} {print $0 }' input awk: cmd. line:1: (FILENAME=VUS FNR=8) fatal: attempt to access field -1 input Chr Start End Ref ... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

Need shell script to compare directories and delete files on target server

Hello, I need help in writing the shell script for below mentioned case. There are 2 servers(server A, server B). A cronjob syncs files between these 2 servers. Existing script is copying files from A to B. This is done using the command rsync. However, the files are not deleted... (2 Replies)
Discussion started by: SravaniVedam11
2 Replies

3. Shell Programming and Scripting

Compare & Copy Directories : Bash Script Help

Beginner/Intermediate shell; comfortable in the command line. I have been looking for a solution to a backup problem. I need to compare Directory 1 to Directory 2 and copy all modified or new files/directories from Directory 1 to Directory 3. I need the directory and file structure to be... (4 Replies)
Discussion started by: Rod
4 Replies

4. UNIX for Dummies Questions & Answers

linux sort command produces strange output

cat a .a ba .b bb .c bc sort a .a .b ba bb bc .c NOTE: .a and .b appears before ba and bb, where as .c appears after bc. In general (3 Replies)
Discussion started by: ajb
3 Replies

5. Homework & Coursework Questions

2. Write a shell script that produces some summary information of the system at a particular moment

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms: 3. The attempts at a solution (include all... (2 Replies)
Discussion started by: jsk319342
2 Replies

6. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

7. UNIX for Dummies Questions & Answers

gzip produces different output from the same input

Hi there, I'm puzzled. Compressing the same file (same name, same md5sum) at two different times will produce a different output. I mean the md5sum of the resulting .gz files are different. Does it make any sens to any of you? I'd like some explanations if you know what's going on. Thanks... (4 Replies)
Discussion started by: chebarbudo
4 Replies

8. Shell Programming and Scripting

read -n1 -r -p "Press..." key / produces error in bash shell script

Hello! Sorry, for my not so perfect english! I want to stop bash shell script execution until any key is pressed. This line in a bash shell script read -n1 -r -p "Press any key to continue..." key produces this error When I run this from the command line usera@lynx:~$ read... (4 Replies)
Discussion started by: linuxinho
4 Replies

9. Shell Programming and Scripting

compare files in two directories and output changed files to third directory

I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together. I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
Discussion started by: bkeep
4 Replies

10. Linux

vgscan produces no output using file descriptors on Oracle Enterprise Linux.

I wrote a simple program which will create a child process to execute a command and the output will be redirected to the file. Please have a look at the following code -> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <fcntl.h> void execute(char **argv) { ... (0 Replies)
Discussion started by: sandiworld
0 Replies
Login or Register to Ask a Question