#!/usr/bin/perl -w use strict; my $Directory= "/var/spool/mail"; my $BadDir= "bad/"; my $BadString= ("\0"x30)."\t\0\0(\0"; my $BadCount= 10; my $ExceptionsFile= "exclude"; my $ExceptionsUpdated; my %Exception; my $SleepLength= 1; chdir( $Directory ) or die "Can't chdir to $Directory: $!\n"; opendir DIR, "." or die "Can't open directory, $Directory: $!\n"; undef $/; while( 1 ) { if( $ExceptionsUpdated != -M $ExceptionsFile ) { open EXCEPT, "< $ExceptionsFile" or die "Can't read $ExceptionsFile: $!\n"; my @except= ; close EXCEPT; chomp( @except ); @Exception{@except}= (1) x @except; } rewinddir( DIR ) or die "Can't rewind directory, $Directory: $!\n"; my $file; while( $file= readdir(DIR) ) { if( $file =~ /^di/ && ! $Exception{$file} ) { if( ! open FILE, "< $file" ) { warn "Can't read $file: $!\n"; next; } my $data= ; close FILE; my $count= ()= $data =~ /\Q$BadString/g; next if $BadCount <= $count; if( ! rename( $file, $BadDir.$file ) ) { warn "Can't rename $file to $BadDir$file: $!\n"; } else { warn "Moved $file to $BadDir$file.\n"; } } } sleep $SleepLength; }