Verifying Filesystem Integrity with CVS
Listing 2. cvschecker.pl
#!/usr/bin/perl
use File::Find;
use strict;
use vars qw(@Files);
my $email = 'root@localhost';
my $host = "192.168.10.5";
my $cvsroot = "/usr/local/hbids_cvs";
my $collectorCmd = "/usr/local/bin/collector.pl";
system "cvs -d $cvsroot checkout -ko $host";
chdir $host;
system "$collectorCmd"; ### get the files from $host
find(\&findfiles, "/home/mbr/${host}");
### check to see if any file has been changed
for my $file (@Files) {
if (`cvs -d $cvsroot commit -m . $file`) {
my $cvsfile = $file;
$cvsfile =~ s|^\S+?$host|$host|;
$cvsfile = $cvsroot ."/" . $cvsfile .",v";
my $prerev = "";
### use rlog to get the previous revision
open RLOG, "rlog $cvsfile|";
my $found = 0;
while (<RLOG>) {
if (/^revision\s(\S+)/) {
$prerev = $1;
$found++;
}
last if ($found == 2);
}
close RLOG;
### get the changes using 'cvs diff'
my $diff = `cvs -d $cvsroot diff -r \
$prerev $file`;
open TMP, "> /tmp/change";
print TMP $diff;
close TMP;
$file =~ s|^\S+?$host||g;
### send an email that contains the changes
`mail -s "Changed file on $host: $file"
$email < /tmp/change`;
}
}
exit 0;
### find all files in the local directory structure,
### but ignore directories and CVS files
sub findfiles() {
my $file = $File::Find::name;
unless (-d $file || $file =~ /CVS/) {
push @Files, $file;
}
return;
}
Subscribe now!
The Latest
Newsletter
Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Tech Tip Videos
- Nov-19-09
- Nov-04-09
Recently Popular
From the Magazine
December 2009, #188
If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.








