On Wed, Oct 17, 2001 at 12:18:07PM -0400, Shane Landrum wrote:

> Hi. I've just started playing with mon, and I like it a lot.
> Thanks much to the author[s]--- it's a great little utility.
> 
> I've got a monitoring problem which I *think* mon should be able
> to handle, but I haven't yet figured out how. I need to monitor
> file changes, but I only want to receive an alert when a file
> was supposed to change around a certain time and didn't.
> 
> Example: My organization gets news feeds from other companies.
> /etc/foo.txt is supposed to be updated 3 times a day; once
> at 9am, once at noon, and once at 5pm. I need to get mail if
> those updates don't happen. In some cases, I may be expecting
> a whole directory full of files to be changed, and I won't
> necessarily know the file names; the files are intended for
> batch processing. 
> 
> Does anyone have a script that does this, or ideas for strategy?
> I've looked at the file-change monitoring script included with
> mon, and it seems to be designed to send alerts on update, rather
> than on not-updated.

I use this program in cron to check if files have changed -- You'll
have to hack it for your requirements and to create the initial checksum 
file, though.

#!/usr/local/bin/perl

use File::Basename;
use Digest::MD5;
use Storable;
use Mail::Send;

$msg = new Mail::Send;
$msg->to('someone');
$msg->subject('File Change Audit');

$fh = $msg->open;

$chksum_file = "/home/clay/chksums.dat";

%foo = %{ retrieve("$chksum_file") };

chdir "/usr/somewhere" or die "err01: $!\n";

open F, "find . -print |" or die "err02: $!\n";
while ($fn = <F>) {
    chomp $fn;
    ($file,$path,$suffix) = fileparse($fn); 
    $path =~ s/\.\//\/usr\/garpac\//;
    chdir "$path" or die "err03: $!\n";
    open G, "$file" or die "err04: $!\n";
    binmode(G);
    $size = (stat($file))[7];
    $md5 = Digest::MD5->new->addfile(*G)->hexdigest; 
    print "$file  $md5\n";
    $name = "$path$file";
    $chksum = {
        NAME  => "$name",
        MD5   => "$md5",
        SIZE  => "$size"
    };
    $byname{ $chksum->{NAME} } = $chksum;
    if ($ck = $foo{"$name"}) {
        $omd5 = $ck->{MD5};
        if ($omd5 ne $md5) {
            print $fh "$name changed: \n";
            print $fh "  MD5  = $md5 / $ck->{MD5}\n";
            print $fh "  Size = $size / $ck->{SIZE}\n\n";
        }
    }
}

store(\%byname, "$chksum_file");
store(\%foo, "$chksum_file.1");

-- 
Clay Irving <[EMAIL PROTECTED]>
I'm so hyper...(said with a very dull voice)  
- Steven Wright 

Reply via email to