Here is a little Fedora-oriented shell script to tell how long it’s been since any program included in a given RPM has been accessed, i.e., used. Packages that show no usage in many days might be considered for deletion.
#! /bin/sh
MINDAYS=${MINDAYS-7}
rpm -q -a "$@" | while read rpm; do
rpm -ql "$rpm" | egrep '/bin|/sbin|/lib' | while read file; do
echo `stat -c '%X' $file 2>/dev/null` $file
done | sort -n | tail -1 |
awk 'BEGIN {CONVFMT="%d"}
{ days=(systime()-$1)/86400
if (days >= '$MINDAYS') {
print "'$rpm'" " " ((systime()-$1)/86400) " days (" $2 ")"
} }'
done
It runs thusly:
% MINDAYS=14 rpm-usage gnome\*
gnome-python2-desktop-2.16.0-1.fc6.x86_64 244 days (/usr/lib64/pkgconfig/gnome-python-desktop-2.0.pc)
gnome-python2-extras-2.14.2-9.fc6.x86_64 69 days (/usr/lib64/pkgconfig/gnome-python-extras-2.0.pc)
gnome-mime-data-2.4.2-3.1.x86_64 299 days (/usr/lib64/pkgconfig/gnome-mime-data-2.0.pc)
gnome-themes-2.16.3-1.fc6.noarch 83 days (/usr/share/icons/HighContrast-SVG/scalable/mimetypes/binary.svg)
Trackback link:
Please enable javascript to generate a trackback url
Cool script though it does have the slight shortcomming in that when a package is upgraded all of its files are accessed. Thus a package may go unused for years but never be caught by this script because the access time keeps getting bumped by updates.
What if one made two scripts rpm-usage and rpm-upgrade.
These scripts use a database with a single table packageAccess, with fields packageName, lastAccess, and lastUpgrade.
packageName is the name of the package, lastAccess is the date of the most recent access of a file in that package (not counting upgrades), and lastUpgrade is the date of the last package upgrade.
When rpm-usage runs it gets the current access date (much like the current script). It then compares this value to lastUpgrade, if the date is newer than lastUpgrade then lastAccess is updated to this more current date. If lastUpgrade is the same then lastAccess is unchanged.
The second script rpm-upgrade, runs a macro when an RPM is upgraded.
First it runs the first script, to make sure the old access time is saved (and stored in lastAccess if appropriate), then it upgrades the rpm, after the upgrade it stores the new access time in the lastUpgrade field.
This way one will be able to spot packages that while being upgraded are never actually used (since their accessDate will never be upgraded). [aluchko] (URL) - 2007-05-11 13:19