5

Slackware: script to detect orphaned libraries and broken symlinks in /lib dirs

view full story
linux-howto

http://www.linuxquestions.org – My recent borked upgrade to -current is possibly still causing me problems with Xorg, and I have learned in the past that having broken stuff in */lib* dirs can lead to weird problems. This inspired me to try to come up with a way to sanity-check the */lib* dirs for broken library symlinks (possibly indicating missing libs) and for libraries that belong to no installed package. If my calculations are correct (i.e. if this script is working as it appears to be) I do have some broken stuff, which *might* be contributing to my inability to upgrade to Xorg 1.7.5 in -current. I've checked the script results manually, and it appears to be accurate, so I figured I'd post it here for a second opinion, and/or because others may find it useful too. I'm not aware of another popular method of doing this, so here it is: orphans.sh File Attachment: Attachment 2955 0cc41d1ebcd28bac91214cc1ab5cdf4a orphans.txt Code: #!/bin/dash # NOTE: As you see above, the shebang points to /bin/dash. If you have no Dash shell # installed, change it to read #!/bin/bash or whatever Bourne-type shell you like. # Simulation has no relevance at this time -- this script ONLY produces an output file # for you to peruse, and you can decide what to do with it. # This script does not change your system. # If $SIMULATION='true' nothing will be changed or deleted: SIMULATION='true' # put the results in this file (in the CWD): RESULT=$(pwd)/orphans.log # create fresh output file: echo "## Slackware check for orphaned/missing libraries: $(date)" > "$RESULT" echo >> "$RESULT" # FYI, this many packages are apparently installed: echo "## Count installed packages: $(ls /var/log/packages | wc -l)" | tee -a "$RESULT" echo >> "$RESULT" # See if there are links pointing to non-existant libraries. # Multiple (identical) results here indicate multiple broken symlinks # are pointing to a non-existant library: echo "## Checking for missing libraries (via broken symlinks)..." | tee -a "$RESULT" echo >> "$RESULT" for LIB in $(ldconfig -v 2>&1 >/dev/null | grep 'Cannot stat' | awk '{print $4}' | tr -d ':'); do   echo "Missing library: $LIB" >> "$RESULT"   printf "Possibly comes from package:" >> "$RESULT"   PKG="$(grep "$LIB" /var/log/packages/*)"   [ ! "$PKG" ] && echo " unknown." >> "$RESULT" || printf "\n$(echo "$PKG" | cut -d: -f1 | awk -F/ '{print $5}').t?z\n" >> "$RESULT"   echo "#" >> "$RESULT" done echo >> "$RESULT" echo "Done." | tee -a "$RESULT" # grab names of lib directories to search, from ld.so.conf and see # if every library on the machine belongs to an installed package: echo "## Searching for orphaned libraries (not belonging to an installed package)..." | tee -a "$RESULT" cat << END >> "$RESULT" ########################################################### # WARNING! If you have for e.g. an NVIDIA driver installed # and have installed it using the nvidia driver installer # instead of pkgtool, you will see "orphaned" files # which do belong to the driver! Don't go crazy on them. # Examples include stuff like these five here (and more): # Orphaned library: /usr/lib64/ libnvidia-tls.so.190.53 # Orphaned library: /usr/lib64/ libnvidia-wfb.so.190.53 # Orphaned library: /usr/lib64/ libvdpau.so.190.53 # Orphaned library: /usr/lib64/ libvdpau_nvidia.so.190.53 # Orphaned library: /usr/lib64/tls/ libnvidia-tls.so.190.53 ########################################################### END cat /etc/ld.so.conf | sort | uniq | \  while read DIR; do   if [ "$DIR" ] && [ -d "$DIR" ]; then     echo "## Searching contents of: $DIR" >> $RESULT     for LIB in $(find "$DIR" -type f -exec basename "{}" \; | egrep '*\.pc$|*\.a$|*\.la$|*\.so\.*' | sort -V | uniq); do       if [ "$LIB" ]; then         # comment next line for slightly faster progress but no visible evidence of progress:         printf "$DIR/$LIB                                                  \r"         [ ! "$(grep "$LIB" /var/log/packages/*)" ] && echo " Orphaned library: $DIR/$LIB" >> "$RESULT"       fi     done   fi   echo >> "$RESULT"  done echo >> "$RESULT" echo "All done!                                                    " | tee -a "$RESULT" # Next line automatically cat's the results file to the screen: # echo "cat $RESULT" && echo && sleep 2 && cat "$RESULT" And here's what the output looks like from my machine: cat orphans.log Code: ## Slackware check for orphaned/missing libraries: Tue Mar  9 07:00:27 UTC 2010 ## Count installed packages: 756 ## Checking for missing libraries (via broken symlinks)... Missing library: /usr/lib64/libsashacrap.so Possibly comes from package: unknown. # Done. ## Searching for orphaned libraries (not belonging to an installed package)... ########################################################### # WARNING! If you have for e.g. an NVIDIA driver installed # and have installed it using the nvidia driver installer # instead of pkgtool, you will see "orphaned" files # which do belong to the driver! Don't go crazy on them. # Examples include stuff like these five here (and more): # Orphaned library: /usr/lib64/ libnvidia-tls.so.190.53 # Orphaned library: /usr/lib64/ libnvidia-wfb.so.190.53 # Orphaned library: /usr/lib64/ libvdpau.so.190.53 # Orphaned library: /usr/lib64/ libvdpau_nvidia.so.190.53 # Orphaned library: /usr/lib64/tls/ libnvidia-tls.so.190.53 ########################################################### ## Searching contents of: /lib ## Searching contents of: /lib64  Orphaned library: /lib64/ld-2.9.so  Orphaned library: /lib64/libBrokenLocale-2.9.so  Orphaned library: /lib64/libanl-2.9.so  Orphaned library: /lib64/libcidn-2.9.so  Orphaned library: /lib64/libcrypt-2.9.so  Orphaned library: /lib64/libc-2.9.so  Orphaned library: /lib64/libdl-2.9.so  Orphaned library: /lib64/libm-2.9.so  Orphaned library: /lib64/libnsl-2.9.so  Orphaned library: /lib64/libnss_compat-2.9.so  Orphaned library: /lib64/libnss_dns-2.9.so  Orphaned library: /lib64/libnss_files-2.9.so  Orphaned library: /lib64/libnss_hesiod-2.9.so  Orphaned library: /lib64/libnss_nisplus-2.9.so  Orphaned library: /lib64/libnss_nis-2.9.so  Orphaned library: /lib64/libpthread-2.9.so  Orphaned library: /lib64/libresolv-2.9.so  Orphaned library: /lib64/librt-2.9.so  Orphaned library: /lib64/libutil-2.9.so ## Searching contents of: /opt/kde3/lib64 ## Searching contents of: /usr/X11R6/lib ## Searching contents of: /usr/X11R6/lib64 ## Searching contents of: /usr/lib ## Searching contents of: /usr/lib64  Orphaned library: /usr/lib64/libGL.la  Orphaned library: /usr/lib64/libGLcore.so.190.53  Orphaned library: /usr/lib64/libGL.so.190.53  Orphaned library: /usr/lib64/libXvMCNVIDIA.a  Orphaned library: /usr/lib64/libXvMCNVIDIA.so.190.53  Orphaned library: /usr/lib64/libcuda.so.190.53  Orphaned library: /usr/lib64/libevent.a  Orphaned library: /usr/lib64/libevent.la  Orphaned library: /usr/lib64/libevent-1.4.so.2.1.3  Orphaned library: /usr/lib64/libevent_core.a  Orphaned library: /usr/lib64/libevent_core.la  Orphaned library: /usr/lib64/libevent_core-1.4.so.2.1.3  Orphaned library: /usr/lib64/libevent_extra.a  Orphaned library: /usr/lib64/libevent_extra.la  Orphaned library: /usr/lib64/libevent_extra-1.4.so.2.1.3  Orphaned library: /usr/lib64/libglx.so.190.53  Orphaned library: /usr/lib64/libnvidia-cfg.so.190.53  Orphaned library: /usr/lib64/libnvidia-tls.so.190.53  Orphaned library: /usr/lib64/libnvidia-tls.so.190.53  Orphaned library: /usr/lib64/libnvidia-wfb.so.190.53  Orphaned library: /usr/lib64/libvdpau.so.190.53  Orphaned library: /usr/lib64/libvdpau_nvidia.so.190.53  Orphaned library: /usr/lib64/libvdpau_trace.so.190.53  Orphaned library: /usr/lib64/nvidia_drv.so ## Searching contents of: /usr/lib64/qt/lib ## Searching contents of: /usr/lib64/seamonkey ## Searching contents of: /usr/lib64/tls  Orphaned library: /usr/lib64/tls/libnvidia-tls.so.190.53 ## Searching contents of: /usr/local/lib ## Searching contents of: /usr/local/lib64 ## Searching contents of: /usr/x86_64-slackware-linux/lib All done! Feedback definitely welcome. Sasha Attached Files orphans.txt (3.3 KB) (HowTos)