Thank you to all who replied to my mail. I basically went out, and grabbed
the Filesys::DiskFree module, and incorporated it into a daemon script.
Thanks so much...

-James

P.S. Incase anyone wants to see the finished product, take a look below.
Thanks!

#!/usr/bin/perl -w



# Local to main these are the variables I will need...
@dirs = ('/','/boot','/home','/src','/usr','/storage');
$maxsize = "0.9";

# Initalize the Filesys::DiskFree package
use Filesys::DiskFree;
$size = Filesys::DiskFree->new();
$size->df();

# Initalize the POSIX package....
use POSIX qw(setsid);

# set the script to be a daemon....
&daemonize;

# Start the loop for the daemon....
while(1) {
    # Parse through my directories...
    foreach $basedir (@dirs) {
        $total = $size->total("$basedir");
        $avail  = $size->avail("$basedir");
        $percent = ($total - $avail) / $total;

        if($percent > $maxsize) {
            print "Woops! $basedir is bigger that $maxsize\n";
            &mail($basedir);
        }

    }

sleep 3600;                     # Check every hour.......
}


sub daemonize {
    my $log = "/var/log/filesize.log";
    my $rootdir = "/";

    chdir($rootdir) or die "Cannot change to $rootdir! Holy Shit! $!\n";
    umask 0;
    open STDIN, '/dev/null'     or die "Cannot open /dev/null: $!\n";
    open STDOUT, ">>$log"       or die "Cannot open $log for STDOUT: $!\n";
    open STDERR, ">>$log"       or die "Cannot open $log for STDERR: $!\n";

    defined(my $pid = fork)     or die "Cannot fork: $!\n";
    exit if $pid;
    setsid                      or die "Cannot start new session: $!\n";

}

sub mail {
    my $dir       = shift(@_);
    my $host      = `uname -n`;
    chomp($host);
    my $subject   = "Spacedaemon: Error on $host\n";
    my $from      = "Spaceadmin\@feathertrip.net";
    my $replyto   = "james\@feathertrip.net";
    my $maxsize   = $maxsize;
    my $mailprog  = "/usr/sbin/sendmail -t";

    open(MAIL,"| $mailprog $replyto") or die "Cannot open $mailprog: $!\n";
    print MAIL "From: $from\n";
    print MAIL "Reply-To: $replyto\n";
    print MAIL "Subject: $subject\n";
    print MAIL "There is a problem with $dir on $host. It is larger than the
maximum size allowed of $maxsize. Thank You!\n\n--Space Admin\n";
    print MAIL ".";
    close(MAIL);
}

James Kelty
Sr. Unix Systems Administratory
The Ashland Agency
[EMAIL PROTECTED]
541.488.0801


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to