#!/usr/bin/perl -w #By Neil Watson on 08/18/01 (watson-wilson.ca) #Usage filehog use strict; use warnings; use File::Find; use CGI qw(:standard); #change this for the locale of final report: my $repdir = "/home/neil"; my @field; my $dir = $ARGV[0]; my $host = `hostname`; chomp($host); my @date = split(/\s+/, `date`); chomp($date[5]); #input open(RAW, ">/tmp/filehog") || die "Could not open /tmp/filehog"; #calls sub wanted find(\&wanted, $dir); close(RAW); #output open(HTML, ">$repdir/hogs_$host.html") || die "Could not open $repdir/hogs_$host.html"; print HTML start_html("Space Hogs on server $host for $date[0], $date[1] $date[2] $date[5]"); print HTML h1("Space Hogs on server $host for$ date[0], $date[1] $date[2] $date[5]")."\n\n"; print HTML h3("These people are shamefully using more than their fair share of disk space. Hopefully, under this public scrutiny, they will change their greedy ways."); print HTML "\n
"; print HTML "\n\n"; print HTML "\n"; print HTML "\t\n"; #sort RAW data system "sort -nr /tmp/filehog|head>/tmp/filehog_sort"; #write final report open(RAW, "/tmp/filehog_sort") || die "Could not open /tmp/filehog_sort"; while () { chomp; s/^\s*//; @field = split(/,/, $_); $field[2] = `grep x:$field[2] /etc/passwd|cut -d: -f1`; chomp($field[2]); print HTML "\n"; print HTML "\t\n"; } close(RAW); print HTML "
Size (MB)\n"; print HTML "\tFile Name and Location\n"; print HTML "\tFile Owner\n"; print HTML "
$field[0]\n"; print HTML "\t$field[1]\n"; print HTML "\t$field[2]\n"; print HTML "
"; print HTML end_html(); close(HTML); system "rm -f /tmp/filehog /tmp/filehog_sort"; sub wanted { my $uid = (lstat($_))[4]; my $size = (lstat($_))[7]; $size = $size/1000000; printf RAW "%5.1f", $size; print RAW ",$File::Find::name,$uid\n"; }