Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2023-09-27 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?