#! /usr/bin/perl -w

my @files = `grep -l 'Your request cannot be completed at this time due to query limit controls.' cache/*`;
if ( @files ) { 
   chomp @files;
   my $files = 'rm ' . join ( ' ', @files );
#   print '-'x40 . "\n$files\n" . '-'x40 . "\n"; 
   print 'Deleting ' . scalar( @files ) . " domain files which were not completely downloaded\n";
   `rm $files`;
}

if ( open BAD, '<badDomains' ) {
   while ( my $line = <BAD> ) {
      my ( $domain,$trash ) = split( "\t", $line );
      if ( -e "cache/$domain.whois" ) {
         print "Deleting bad domain file $domain\n";
         `rm cache/$domain.whois`;
      }
   }
   close BAD;
}

print "Now, looking for new domains to download\n";
`./checkBind.pl | ./checkDomains.pl`;
print "Your cache should be up to date\n";
1;
