summaryrefslogtreecommitdiffstats
path: root/misc-utils/chkdupexe.pl
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:33 +0100
committerKarel Zak2006-12-07 00:25:33 +0100
commit726f69e29ca9d4842f3acb20fffd2466fda62c09 (patch)
treeabbc1b6e9bfb0dfe32e81a83648e261ccb2d5a5f /misc-utils/chkdupexe.pl
parentImported from util-linux-2.2 tarball. (diff)
downloadkernel-qcow2-util-linux-726f69e29ca9d4842f3acb20fffd2466fda62c09.tar.gz
kernel-qcow2-util-linux-726f69e29ca9d4842f3acb20fffd2466fda62c09.tar.xz
kernel-qcow2-util-linux-726f69e29ca9d4842f3acb20fffd2466fda62c09.zip
Imported from util-linux-2.5 tarball.
Diffstat (limited to 'misc-utils/chkdupexe.pl')
-rw-r--r--misc-utils/chkdupexe.pl56
1 files changed, 56 insertions, 0 deletions
diff --git a/misc-utils/chkdupexe.pl b/misc-utils/chkdupexe.pl
new file mode 100644
index 000000000..117d20fa5
--- /dev/null
+++ b/misc-utils/chkdupexe.pl
@@ -0,0 +1,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);