Try this:
- tye#!/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"; $/= $BadString; while( 1 ) { if( $ExceptionsUpdated != -M $ExceptionsFile ) { open EXCEPT, "< $ExceptionsFile" or die "Can't read $ExceptionsFile: $!\n"; my @except= <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 $line; for( 1..$BadCount ) { last unless defined( $line= <FILE> ); } close FILE; next if ! $line || ! chomp($line); if( ! rename( $file, $BadDir.$file ) ) { warn "Can't rename $file to $BadDir$file: $!\n"; } else { warn "Moved $file to $BadDir$file.\n"; } } } sleep $SleepLength; }
In reply to (tye)Re: Hitting a moving target (transient files)
by tye
in thread Hitting a moving target (transient files)
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |