Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

disk monitor

by fuzzysteve (Beadle)
on Nov 16, 2001 at 18:20 UTC ( [id://125820]=CUFP: print w/replies, xml ) Need Help??

Nothing fancy, just emails someone a quick list of how the disks are doing for free space.
#!/usr/bin/perl -w use strict; ## Disk Monitor for linux boxes. ## To be run daily. ## Grabs the disk usage from the computer and emails it to an\@email.c +om use Filesys::DiskFree; use Sys::Hostname; ## Get the ip address of the local interface. my $ipaddr; $_ = `/sbin/ifconfig eth0`; (/inet addr:((\d{1,3}\.?){4})/m) ? ($ipaddr = $1) : (warn 'ifconfig +failed'); ## Set up the top of the mail's body and its subject with identifying +info my $subject="Subject: Disk Usage for ".hostname()." $ipaddr\n +"; my $body=localtime()."\n\n".hostname()."\n\n$ipaddr\n\n"; my $handle = new Filesys::DiskFree; $handle->df(); my @disks=$handle->disks(); my $disk; foreach $disk (@disks){ my $dt=$handle->total($disk)/1024; my $df= $handle->avail($disk)/1024; my $du=int(($df/$dt)*100); $body.="$disk has $du% free\n" } ## Send it by email my $sendmail= "/usr/sbin/sendmail -t"; my $reply_to="Reply-to: an\@email.com\n"; my $to="To: an\@email.com\n"; my $from="From: an\@email.com\n"; open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!"; print SENDMAIL $to; print SENDMAIL $from; print SENDMAIL $reply_to; print SENDMAIL $subject; print SENDMAIL "Content-type: text/plain\n\n"; print SENDMAIL $body; close(SENDMAIL);

Replies are listed 'Best First'.
Example of email
by fuzzysteve (Beadle) on Nov 16, 2001 at 18:28 UTC
    The subject is:

    Disk usage for localhost 10.2.0.22

    The body is:
    Fri Nov 16 13:04:33 2001 localhost 10.2.0.22 / has 66% free /boot has 65% free /var has 91% free /home has 92% free /usr has 82% free


    Obviously it works better if you have a meaningful hostname.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found