summaryrefslogtreecommitdiffstats
path: root/misc-utils/chkdupexe.pl
blob: 117d20fa583a08f69e142c6234914c2710bfec3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
#
# chkdupexe version 2.0
#
# Simple script to look for and list duplicate executables and dangling
# symlinks in the system executable directories.
#
# Copyright 1993 Nicolai Langfeldt. Distribute under gnu copyleft
#  (included in perl package)
#
# Modified 1995-07-04 Michael Shields <shields@tembel.org>
#     Don't depend on GNU ls.
#     Cleanups.
#     Merge together $ENV{'PATH'} and $execdirs.
#     Don't break if there are duplicates in $PATH.
# 

$execdirs='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/local/bin:/local/sbin:/usr/X11/bin:/usr/bin/X11:/usr/local/X11/bin:/local/X11/bin:/usr/TeX/bin:/usr/tex/bin:/usr/local/graph/bin:/usr/games:/usr/local/games:/usr/intervies/bin/LINUX';

DIRECTORY:
foreach $dir (split(/:/, "$execdirs:$ENV{'PATH'}")) {

  # Follow symlinks and make sure we haven't scanned this directory already.
  while (-l $dir) {
    $newdir = readlink($dir);
    print "Dangling symlink: $dir\n" unless $newdir;
    $dir = $newdir;
    next DIRECTORY if $seendir{$dir}++;
  }

  opendir(DIR,$dir) || (warn "Couldn't opendir($dir): $!\n", next);
  foreach $_ (readdir(DIR)) {
    lstat("$dir/$_");
    if (-l _) {
      ($dum)=stat("$dir/$_");
      # Might as well report these since we discover them anyway
      print "Dangling symlink: $dir/$_\n" unless $dum;
      next;
    }
    next unless -f _ && -x _;	# Only handle regular executable files
    if ($count{$_}) {
      $progs{$_}.=" $dir/$_";
      $count{$_}++;
    } else {
      $progs{$_}="$dir/$_";
      $count{$_}=1;
    }
  }
  closedir(DIR);
}

open(LS,"| xargs ls -ldU");
while (($prog,$paths)=each %progs) {
  print LS "$paths\n" if ($count{$prog}>1);
}
close(LS);