#!/bin/bash - #=============================================================================== # # FILE: zerobytefile-chk.sh # # USAGE: ./zerobytefile-chk.sh # # DESCRIPTION: Finds zero byte files in system folders and lists them # Will also ask to attempt to reinstall package # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Roger Zauner (rdz), # COMPANY: # CREATED: 01/12/2011 11:49:15 AM AKST # REVISION: --- #=============================================================================== set -o nounset # Treat unset variables as an error #set -o xtrace # Enable trace debugging # Find only zero byte files, omitting /usr/src/ files sudo find /usr -not -path "*/usr/src/*" -size 0 > /tmp/zero-byte-file.log sudo chmod a+r /tmp/zero-byte-file.log # read in this listing and find each file's package owner { while read FILENAME; do qfile ${FILENAME} done } < /tmp/zero-byte-file.log > /tmp/package.log # Only want package name field (omit filenames causing package name to be duplicated) cut --delimiter=" " --fields=1 < /tmp/package.log > /tmp/package.log.1 # get rid redundant package names # TODO: this isn't working for some reason, debug! uniq --unique < /tmp/package.log.1 > /tmp/package.log.2 # sort sort < /tmp/package.log.2 > /tmp/package.log.3 # ask to reinstall packages? printf "These are the packages I will reinstall:\n" cat /tmp/package.log.3 printf "Do you wish to reinstall these packages?\n" printf "(This requires root privilages.)\n" select yn in "Yes" "No"; do case $yn in Yes ) continue;; No ) exit;; esac done # reinstall packages as previously requested for pkg_name in `< /tmp/package.log.3`; do sudo emerge $pkg_name done