Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to cleanly identify available file system space

by neilwatson (Curate)
on Sep 05, 2006 at 20:10 UTC ( #571323=note: print w/ replies, xml ) Need Help??


in reply to How to cleanly identify available file system space

#!/usr/bin/perl -w use strict; use warnings; #usage: diskspace <number between 0 and 100> my $diskuse = $ARGV[0]; my $recipient = 'support@example.com'; #who gets the report my $dfrep = `df -k`; #get partition report my @partitions = split(/\n/,$dfrep); # split report my (@full, @ele, $usage, $x, $i); my $hostname = `hostname`; chomp($hostname); #check syntax unless ($diskuse > 0 || $diskuse < 100) { print "\nUsage: spaceuse <n>\n"; print "Where n is the maximum percentage of space, in use by " +; print "any disk partition\n"; } #check for partitions whose percent full is #greater than or equal to the percent entered #by the user. foreach $i (@partitions) { $_ = $i; if (m/(\d{1,2})%/) {$usage = $1} if ($diskuse <= $usage) { push(@full,$x) } $x++; } #create and mail report if ($#full != 0) { open(MAIL, "|mail -s \"Diskspace Warning\" $recipient"); print MAIL "\nWarning from $hostname\n"; print MAIL "These Partitions are dangerously full:\n\n"; for (@full) { $_++; $_--; #converts scalar to numberic $partitions[$_] =~ s/\s+/\t/g; @ele = split(/\t/, $partitions[$_]); printf MAIL "%13s %11s %11s %11s %4s %13s\n", $ele[0], + $ele[1], $ele[2], $ele[3], $ele[4], $ele[5]; } close(MAIL); }

Neil Watson
watson-wilson.ca


Comment on Re: How to cleanly identify available file system space
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://571323]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2014-12-25 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls