5569l2 Listing 2: cvschecker.pl 1 #!/usr/bin/perl 2 3 use File::Find; 4 use strict; 5 use vars qw(@Files); 6 7 my $email = 'root@localhost'; 8 my $host = "192.168.10.5"; 9 my $cvsroot = "/usr/local/hbids_cvs"; 10 my $collectorCmd = "/usr/local/bin/collector.pl"; 11 12 system "cvs -d $cvsroot checkout -ko $host"; 13 chdir $host; 14 system "$collectorCmd"; ### get the files from $host 15 16 find(\&findfiles, "/home/mbr/${host}"); 17 18 ### check to see if any file has been changed 19 for my $file (@Files) { 20 if (`cvs -d $cvsroot commit -m . $file`) { 21 my $cvsfile = $file; 22 $cvsfile =~ s|^\S+?$host|$host|; 23 $cvsfile = $cvsroot ."/" . $cvsfile .",v"; 24 my $prerev = ""; 25 26 ### use rlog to get the previous revision 27 open RLOG, "rlog $cvsfile|"; 28 my $found = 0; 29 while () { 30 if (/^revision\s(\S+)/) { 31 $prerev = $1; 32 $found++; 33 } 34 last if ($found == 2); 35 } 36 close RLOG; 37 38 ### get the changes using 'cvs diff' 39 my $diff = `cvs -d $cvsroot diff -r \ 40 $prerev $file`; 41 open TMP, "> /tmp/change"; 42 print TMP $diff; 43 close TMP; 44 $file =~ s|^\S+?$host||g; 45 46 ### send an email that contains the changes 47 `mail -s "Changed file on $host: $file" \ 48 $email < /tmp/change`; 49 } 50 } 51 exit 0; 52 53 ### find all files in the local directory structure, 54 ### but ignore directories and CVS files 55 sub findfiles() { 56 my $file = $File::Find::name; 57 unless (-d $file || $file =~ /CVS/) { 58 push @Files, $file; 59 } 60 return; 61 }