On Wed, Sep 17, 2003 at 12:03:17AM -0500, [EMAIL PROTECTED] wrote:
> Doing without -path, however, is a little clunky.   
> 
> find /var/spool/qmailscan -type f \( ! -name '*.log' ! -name '*.txt' ! 
> -name '*.db' \)  -mtime +1 -print  |egrep -v "quarantine/|archives/"  
> | xargs /usr/bin/rm -f

Hooray for perl.

==== clean_files.pl ====
#!/usr/bin/perl

# This program will remove all files in the qmailscan directory older
# older than one day, except in the quarantine and archive directories,
# or if the file has a .log, .txt , or .db extension.

use strict;
use File::Find;
use File::Path;

my $currenttime = scalar time();

sub cleanup_files {

        my $file=$File::Find::name,"\n";
        # Skip if it matches things we want to keep.
        next if -l $file;            
        next if $file =~ /quarantine/;
        next if $file =~ /archive/;  
        next if $file =~ /\.log/; 
        next if $file =~ /\.txt/;  
        next if $file =~ /\.db/;
        next if -d $file and $file =~ /working/;
        # Subtract current time from file's mtime.
        my $timediff = $currenttime - (stat($file))[9];
        # Skip if less than a day old.         
        next if $timediff < 86400;   
        # Uncomment for debugging.
        # print "$file $timediff \n";
        if (-d $file) {
        rmtree  ($file) or warn "Couldn't rmdir $file: $!";
        } else {      
        unlink ($file) or warn "Couldn't unlink $file: $!";          
        }             
}
 
finddepth(\&cleanup_files, '/var/spool/qmailscan');
========

We could do without use File::Path and use rmdir instead of rmtree, but 
if there are any mime attachments with the extension .txt, .db, or .log, 
rmdir won't delete a directory with files in it.

--
Jason


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Qmail-scanner-general mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/qmail-scanner-general

Reply via email to