#!/usr/bin/perl -w #By Neil Watson on 08/18/01 (watson-wilson.ca) #Usage filehog <directory> 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 <i>$host</i> 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 wil +l change their greedy ways."); print HTML "\n<hr>"; print HTML "\n<table>\n"; print HTML "<tr>\n"; print HTML "\t<th>Size (MB)<th>\n"; print HTML "\t<th>File Name and Location<th>\n"; print HTML "\t<th>File Owner<th>\n"; print HTML "<tr>\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_sor +t"; while (<RAW>) { chomp; s/^\s*//; @field = split(/,/, $_); $field[2] = `grep x:$field[2] /etc/passwd|cut -d: -f1`; chomp($field[2]); print HTML "<tr>\n"; print HTML "\t<td>$field[0]<td>\n"; print HTML "\t<td>$field[1]<td>\n"; print HTML "\t<td>$field[2]<td>\n"; print HTML "<tr>\n"; } close(RAW); print HTML "</table>"; 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"; }

Edited by Ovid 2001-11-06


In reply to Spacehog by neilwatson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.