Shell script: lsb-libstats, was: Re: script: scan-libraries
OK, I'm a day late, and a dollar short. I'm not the perl programmer that
Daniel is, and it appears not the shell script programmer I need to be ;-)
I did a shell script version of the perl script published by Daniel. (I
was about half done when he posted) I'm still not completely satisfied
with the results for two reasons:
First, if you look at the condensed report below, you will see a
discrepancy of 2 between the number of programs using libc6, and the
number using ld-linux. This should not be, but seemed to crop in during
the look at the /usr directories.
There is another report generated that gives each binary and the libraries
that it is linked to. I grepped this file for lines not containing
ld-linux and only got comments and programs using libc5 (which doesn't use
the libc6 loader, but ld.so instead)
This means that according to the first report there are no programs which
use libc6 but not ld-linux, while the counting report says otherwise. Can
anyone see what is wrong with my logic in the script?
Second, several programs (ldconfig and ldd) are staticly linked, and show
up in the first report. However there is no report of the library "static"
in the second report. I, at first, thought that this was because ldd was
returning false under these conditions, but now, with this other bug, I'm
not so sure. Can anyone see the "duhh" that I don't see?
-------------- begin paste ----------------------
<Subtotal lists deleted>
Total library use for /bin and /sbin:
129 libc.so.6
129 /lib/ld-linux.so.2
10 libcrypt.so.1
7 libnsl.so.1
7 libext2fs.so.2
7 libcom_err.so.2
5 libuuid.so.1
4 libncurses.so.3.4
4 libdl.so.2
3 libreadline.so.2
3 libncurses.so.4
3 libm.so.6
2 libe2p.so.2
1 libutil.so.1
1 libslang.so.1
1 libslang.so.0.99.38
1 libproc.so.1.2.6
1 libgdbm.so.1
1 libdb.so.2
<Subtotal lists deleted>
Total library use for /bin, /sbin, /usr/bin, and /usr/sbin:
805 libc.so.6
803 /lib/ld-linux.so.2
140 libm.so.6
89 libcrypt.so.1
63 libnsl.so.1
49 libncurses.so.3.4
31 libncurses.so.4
23 libstdc++.so.2.7.2
22 libresolv.so.2
18 libdl.so.2
16 libX11.so.6
14 libz.so.1
14 libdb2.so.2
14 libc.so.5
13 libutil.so.1
13 libext2fs.so.2
13 libcom_err.so.2
12 libdb.so.2
12 libbfd-2.9.1.so.0
11 libproc.so.1.2.6
11 libXext.so.6
10 libreadline.so.2
9 libXt.so.6
9 libSM.so.6
9 libICE.so.6
8 libstdc++-libc6.0-1.so.2
8 libgdbm.so.1
7 libtcl7.6.so.1
6 libuuid.so.1
6 libsp.so.1
6 libgmp2.so.2
5 libtk4.2.so.1
5 libpng.so.0
4 libe2p.so.2
4 libdpkg.so.0
4 libXmu.so.6
4 libXaw.so.6
3 libslang.so.1
3 libncurses.so.3.0
3 libgpm.so.1
2 libvgagl.so.1
2 libvga.so.1
2 libstdc++.so.2.8
2 libslang.so.0.99.38
2 librpm.so.1.0
2 libpng.so.2
2 libpaper.so.1
2 libm.so.5
2 libbuild.so.1.0
2 ld-linux.so.2
1 libungif.so.3
1 libtiff.so.3
1 libtermcap.so.2
1 libstyle.so.1
1 libssl.so.0
1 libss.so.2
1 libspgrove.so.1
1 libpwdb.so.0
1 libpcap.so.0
1 libpam.so.0
1 libopcodes-2.9.1.so.0
1 libnewt.so.0.21
1 libjpeg.so.6b
1 libjpeg.so.6a
1 libjpeg.so.62
1 libgtk.so.1
1 libgrove.so.1
1 libglib.so.1
1 libgdk_imlib.so.1
1 libgdk.so.1
1 libg++.so.2.7.2
1 libcrypto.so.0
1 libXm.so.1
1 libXi.so.6
<Subtotal lists deleted>
Total library use for /bin, /sbin, /usr/bin, /usr/sbin, /usr/X11R6/bin, /usr/games:
897 libc.so.6
895 /lib/ld-linux.so.2
163 libm.so.6
90 libcrypt.so.1
89 libX11.so.6
74 libXext.so.6
63 libnsl.so.1
54 libICE.so.6
53 libSM.so.6
52 libXt.so.6
49 libncurses.so.3.4
43 libXmu.so.6
33 libncurses.so.4
23 libstdc++.so.2.7.2
23 libXaw.so.6
22 libz.so.1
22 libresolv.so.2
21 libdl.so.2
14 libdb2.so.2
14 libc.so.5
13 libutil.so.1
13 libext2fs.so.2
13 libcom_err.so.2
12 libdb.so.2
12 libbfd-2.9.1.so.0
11 libproc.so.1.2.6
10 libreadline.so.2
9 libstdc++-libc6.0-1.so.2
8 libgdbm.so.1
7 libtcl7.6.so.1
7 libolgx.so.3
6 libxview.so.3
6 libuuid.so.1
6 libsp.so.1
6 libgmp2.so.2
5 libtk4.2.so.1
5 libpng.so.0
5 libjpeg.so.6a
5 libXpm.so.4
5 libXi.so.6
4 libtiff.so.3
4 libe2p.so.2
4 libdpkg.so.0
3 libslang.so.1
3 libpng.so.2
3 libncurses.so.3.0
3 libgpm.so.1
2 libvgagl.so.1
2 libvga.so.1
2 libstdc++.so.2.8
2 libslang.so.0.99.38
2 librpm.so.1.0
2 libpaper.so.1
2 libm.so.5
2 libjpeg.so.62
2 libgtk.so.1
2 libglib.so.1
2 libgdk.so.1
2 libbuild.so.1.0
2 libXIE.so.6
2 ld-linux.so.2
1 libungif.so.3
1 libtermcap.so.2
1 libstyle.so.1
1 libssl.so.0
1 libss.so.2
1 libspgrove.so.1
1 libpwdb.so.0
1 libpcap.so.0
1 libpam.so.0
1 libopcodes-2.9.1.so.0
1 libnewt.so.0.21
1 libjpeg.so.6b
1 libgrove.so.1
1 libgdk_imlib.so.1
1 libg++.so.2.7.2
1 libcrypto.so.0
1 libXtst.so.6
1 libXm.so.1
1 libXaw3d.so.6
----------------- end paste ----------------
Luck,
Dwarf
--
_-_-_-_-_- Author of "The Debian Linux User's Guide" _-_-_-_-_-_-
aka Dale Scheetz Phone: 1 (850) 656-9769
Flexible Software 11000 McCrackin Road
e-mail: dwarf@polaris.net Tallahassee, FL 32308
_-_-_-_-_-_- See www.linuxpress.com for more details _-_-_-_-_-_-_-
#!/bin/sh
# Name: lsb-libstsats
# Description: This script collects statistics on the libraries used by
# executables found in /bin, /sbin, /usr/bin, and /usr/sbin and produces
# the following reports:
#
# libs-by-bin : for each binary executable found, list every library
# to which it is linked.
#
# lib-bin-count: for each library, list the total number of binaries
# which are linked to it. The number is given first,
# with the binary name after, to allow the list to be
# sorted by count.
#
#
# Copyright (C) 1999 Dale Scheetz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# On a Debian system a copy of the GPL can be found in /usr/doc/copyright
#
#
# Define report names
#
RPT1=libs-by-bin
RPT2=lib-bin-count
#
# Declare functions
#
CollectDir ()
{
echo List of libraries for binaries found in $1: >>$RPT1
FIRST=ON
for name in `cd $1 ; ls` ; do
if ldd $1/$name > /dev/null 2>&1 ; then
if [ $FIRST = ON ] ; then
FIRST=OFF
else
echo >>$RPT1
fi
echo -n "$name : " >>$RPT1
FLAG=ON
for lib in `ldd $1/$name | awk '{ print $1 }'` ; do
if [ $FLAG = ON ] ; then
FLAG=OFF
else
echo -n ", " >>$RPT1
fi
echo -n "$lib" >>$RPT1
echo $lib >>HoldList
done
fi
done
echo . >>$RPT1
}
CountLibs ()
{
HoldName=nothing
NameCount=0
for name in `sort HoldList` ; do
if [ $name = $HoldName ] ; then
NameCount=$(($NameCount+1))
else
if [ $NameCount != 0 ] ; then
echo $NameCount $HoldName >>SubTotal
NameCount=1
HoldName=$name
else
NameCount=1
HoldName=$name
fi
fi
done
}
CollectData ()
{
CollectDir $1
CountLibs
echo Total library use for $1: >>$RPT2
sort -nr SubTotal >>$RPT2
echo >>$RPT2
cat HoldList >>RunningTotal
rm SubTotal HoldList
}
CollectCount ()
{
cat RunningTotal >HoldList
CountLibs
echo Total library use for $1: >>$RPT2
sort -nr SubTotal >>$RPT2
echo >>$RPT2
rm SubTotal HoldList
}
#
# Do preliminary cleanup
#
rm -f $RPT1 $RPT2
rm -f HoldList SubTotal
rm -f RunningTotal
#
# First collect statistics on /bin
#
CollectData /bin
#
# Next collect statistics on /sbin
#
CollectData /sbin
#
# Give the collected count for /bin and /sbin
#
CollectCount "/bin and /sbin"
#
# Next collect statistics on /usr/bin
#
CollectData /usr/bin
#
# And then for /usr/sbin
#
CollectData /usr/sbin
#
# Give the collected count for /bin, /sbin, /usr/bin, and /usr/sbin
#
CollectCount "/bin, /sbin, /usr/bin, and /usr/sbin"
#
# Now collect data from /usr/X11R6/bin
#
CollectData /usr/X11R6/bin
#
# Now collect the data from /usr/games
#
CollectData /usr/games
#
# Give the collected count for /bin, /sbin, /usr/bin, /usr/sbin
# /usr/X11R6/bin, and /usr/games
#
CollectCount "/bin, /sbin, /usr/bin, /usr/sbin, /usr/X11R6/bin, /usr/games"
#
# Clean up
#
rm RunningTotal
Reply to: