1828658 Members
6983 Online
109983 Solutions
New Discussion

Re: sdiff script help

 
SOLVED
Go to solution
SM_3
Super Advisor

sdiff script help

Hello

I need to scripting help, I'm usless at scripting.

I'd like a script that comapres files in 1 directory with another directory.
Would it be possible to port such a script across different unix flavours?

Thanks.
7 REPLIES 7
Pete Randall
Outstanding Contributor
Solution

Re: sdiff script help

First take a look at "man dircmp" to see if that doesn't do what you want.


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: sdiff script help

Hi:

See the manpages for 'diff'. This will compare and report the differences for files or files within two directories.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: sdiff script help

Hi (again):

If you truly mean 'sdiff' have a look too at its manpages too. Both 'diff' and 'sdiff' are generalized to UNIX.

http://www.docs.hp.com/en/B2355-90689/diff.1.html

http://www.docs.hp.com/en/B2355-90690/sdiff.1.html

Regards!

...JRF...
Rodney Hills
Honored Contributor

Re: sdiff script help

If you are only looking to compare file names, then maybe the following-

ls /dir1 >/tmp/f1
ls /dir2 >/tmp/f2
comm -23 ; # display names in /dir1 but not /dir2
comm -13 ; # display names in /dir2 but not /dir1

HTH

-- Rod Hills
There be dragons...
SM_3
Super Advisor

Re: sdiff script help

The actual directories have many, many subdirectories.
Will this make a difference, dont have access to the servers right now to try out your suggestions?

thanks
Arturo Galbiati
Esteemed Contributor

Re: sdiff script help

man dircmp

NAME
dircmp - directory comparison

SYNOPSIS
dircmp [-d] [-s] [-wn] dir1 dir2

DESCRIPTION
dircmp examines dir1 and dir2 and generates various tabulated
information about the contents of the directories. Sorted listings of
files that are unique to each directory are generated for all the
options. If no option is entered, a sorted list is output indicating
whether the filenames common to both directories have the same
contents.

-d Compare the contents of files with the same name in both
directories and output a list telling what must be
changed in the two files to bring them into agreement.
The list format is described in diff(1).

-s Suppress messages about identical files.

-wn Change the width of the output line to n characters. The
default width is 72.


HTH,
Art
Rodney Hills
Honored Contributor

Re: sdiff script help

If you have many servers that are suppose to have the same directory structure and you are looking for discrepencies, then a perl script would provide you the most power. (Assuming you have openssh installed and have configured all your servers).

#!/usr/bin/perl
@servers=qw/moe larry curly/;
foreach $server (@servers) {
open(INP,"ssh $server 'find /yourdir -print|'");
while() {
chomp;
push(@{$hold{$_},$server);
}
close(INP);
}
foreach $dir (sort keys %hold) {
printf "%40s %s\n",$dir,join(",",@{$hold{$dir}});
}

This will list all the files and the servers they reside on. You could modify the script to only display those files that are not on all the servers.

HTH

-- Rod Hills
There be dragons...