Article 12786 of alt.sources:
Newsgroups: alt.sources
Path: nntpd.lkg.dec.com!crl.dec.com!crl.dec.com!caen!spool.mu.edu!howland.reston.ans.net!Germany.EU.net!news.dfn.de!fu-berlin.de!news.belwue.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!inka.de!bigred.inka.de!not-for-mail
From: Olaf Titz <olaf@bigred.inka.de>
Subject: findbindups - find duplicate binaries
Date: 08 Sep 1995 18:12:10 GMT
Keywords: UNIX system maintenance perl
Message-ID: <DJM4BK7J@bigred.inka.de>
Followup-To: alt.sources.d
Lines: 103
Organization: private Linux site, southern Germany

From the quick'n'dirty department:

Here is one of the programs that surely already have been written a
thousand times, but anyway. This one searches your PATH for duplicate
programs of the same name (e.g. /usr/bin/emacs vs. /usr/local/bin/emacs) 
and shows them in a way that you can quickly figure out what is what.

Deficiencies: 
 - Tested exactly once.
 - Should figure out links (hard and symbolic).
 - Horribly slow (damn O(n^2) algorithms) and wastes processes.

olaf

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  findbindups
# Wrapped by olaf@bigred.inka.de on Fri Sep  8 20:11:11 1995
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'findbindups' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'findbindups'\"
else
echo shar: Extracting \"'findbindups'\" \(1144 characters\)
sed "s/^X//" >'findbindups' <<'END_OF_FILE'
X#!/usr/bin/perl
X# Find executables of same name in more than one element of PATH.    -*-perl-*-
X# ot. 1995-09-08
X
X$ls="/bin/ls -l";
X
Xselect STDERR; $|=1;
X@P = split(/:/, $ENV{PATH});
Xforeach $i (0..$#P) {
X    if (opendir(D, $P[$i])) {
X	chdir $P[$i] || die "chdir $P[$i]";
X	print "Searching $P[$i]...";
X	$cnt=0;
X	local(*E) = "Exec$i";
X	while ($_=readdir(D)) {
X	    if (-x $_ && -f $_) { # file is executable
X		++$cnt;
X		$E{$_} =1;
X	    }
X	}
X	closedir D;
X	print " $cnt executables\n";
X    } else {
X	print "Error opening $i\n";
X    }
X}
X
Xprint "Finding duplicates...";
X$cnt=0;
Xforeach $i (0..$#P) {
X    local(*E) = "Exec$i";
X    foreach $k (keys %E) {
X	foreach $j (0..$#P) {
X	    $j==$i && next;
X	    local(*F) = "Exec$j";
X	    if ($F{$k}) {
X		push(@D, "$P[$i]/$k");
X		++$cnt;
X		if (++$cnt0>10) {
X		    $cnt0=0; print "."; }
X	    }
X	}
X    }
X}
Xprint " $cnt total files are dups.\n";
X
Xselect STDOUT; $|=1;
Xforeach $i (sort bncmp @D) {
X    system "$ls $i";
X    # ls sorts multiple args by itself - grrr
X}
Xexit 0;
X
Xsub bncmp {
X    # sort by basename
X    local(@c) = split(/\//, $a);
X    local(@d) = split(/\//, $b);
X    return ($c[$#c] cmp $d[$#d]);
X}
END_OF_FILE
if test 1144 -ne `wc -c <'findbindups'`; then
    echo shar: \"'findbindups'\" unpacked with wrong size!
fi
chmod +x 'findbindups'
# end of 'findbindups'
fi
echo shar: End of shell archive.
exit 0

-- 
___        Olaf.Titz@inka.de or @{stud,informatik}.uni-karlsruhe.de       ____
__ o           <URL:http://www.inka.de/~bigred/>     <IRC:praetorius>
__/<_              >> Just as long as the wheels keep on turning round
_)>(_)______________ I will live for the groove 'til the sun goes down << ____


