Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I got tired of finding gigantic tumor-like growths left over from the prior sysadmin's lack of filesystem caretaking, so I wrote this little script. When invoked, it sniffs around for bloated files and emails me a list of the main offenders. In this case, it looks for the largest 100 files above 4MB (4096K, ala 8192 blocks).. Feel free to tweak to your hearts delight.
#!/usr/bin/perl ### ### BloatDetector.pl v0.1 written 031405:1749 by BJP ### ### Builds a report showing the top 100 biggest-sized files, excluding ### oracle stuff, backups, etc... Thats what the back|archiv|ora excl +usion stuff does. :) ### use Mail::Sendmail; $reportFile="/tmp/bloatdetector.tmp"; $recipient="youremailaddress\@goes.here.com"; chomp($hostName=`hostname`); # $HOSTNAME is non-ubiquitous. Ugh. $sender=$ENV{"USER"}."\@".$hostName; chomp($dateStamp=`date`); print "BloatDetector: Recipient is [$recipient]\n"; print "BloatDetector: Sender is [$sender]\n"; print "BloatDetector: Scanning files..This may take a while.\n"; @bloatedFiles = `find / -depth -size +8192 -ls| grep -i -v -E \"back|a +rchiv|ora?\"| sort -r -n +6 | cut -d" " -f2- | head -n100`; open(FILE,"+>>$reportFile") or die ("BloatDetector: Can't open tempora +ry logfile. My life was short, yet sweet -- grieve not for me, my fri +end."); print "BloatDetector: Preparing report..\n"; print FILE "\n\n\nHere's the latest BloatDetector report from $hostNam +e..\n\n"; foreach $line (@bloatedFiles) { print FILE "$line"; } chomp($endTime=`date`); print FILE "\n\n"; print FILE "Time invoked : $dateStamp\n"; print FILE "Time completed : $endTime"; close(FILE); open(REPORT,$reportFile); @report = <REPORT>; chomp(@report); close(REPORT); %mail=( To => $recipient, From => $sender, Subject => "BloatDetector Results for ".$dateStamp." from ".$s +ender, Message => join("\n",@report)); print "BloatDetector: Sending report..\n"; sendmail(%mail); # a-la-peanut-butter-sandwiches! print "BloatDetector: Exiting..\n"; unlink $reportFile;

In reply to Bloated File Detector for Unix Boxes by bpoag

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?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-16 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found