O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  

Buy the book!
Linux Server Hacks
By Rob Flickenger
January 2003
More Info

Disk Age Analysis
Easily identify which parts of your disk change frequently
Listing: diskage
[Discuss (0) | Link to this hack]

Listing: diskage

# Disk aging report generator
# Written by Seann Herdejurgen
# May 1998

use File::Find;

# Initialize variables

# Check for verbose flag
if ($ARGV[0] eq "-v") {

$ARGV[0]=$ENV{'PWD'} if ($ARGV[0] eq "");

foreach $dir (@ARGV) {
foreach $level (@levels) {
print("\nDisk aging analysis for $dir:\n\n");
print (" mod acc size file\n") if ($verbose);

# Traverse desired filesystems

print(" last num last num\n");
print(" Age (days) modified files accessed files\n");

foreach $level (@levels) {
printf("%4d - %4d %8d Kb %5d %8d Kb %5d\n",$lastlevel,$level,$modified{$level}/1024,$mfiles{$level},$accessed{$level}/1024,$afiles{$level});

printf(" ----------- ----- ----------- -----\n");
printf(" Total %8d Kb %5d %8d Kb %5d\n",$msize,$mtotal,$asize,$atotal);


sub wanted {
(($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = lstat($_));
$mod=int(-M _);
$acc=int(-A _);
foreach $level (@levels) {
if ($mod<=$level) { $modified{$level}+=$size; $mfiles{$level}++; last; }
foreach $level (@levels) {
if ($acc<=$level) { $accessed{$level}+=$size; $afiles{$level}++; last; }
printf("%4d %4d %6d %s\n",$mod,$acc,$size,$_) if ($verbose);

O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.