Originally to: Hampton, Paul * Hampton, Paul's head hit the keyboard and wrote: HP> Hi all HP> Does anyone know of a way or a script to delete old files, say that are HP> older than a month? Below is a script that I use with Fidogate. Basically it deletes any files older than 45 days. also deletes .desc/$file.desc It reads it's list from a file which starts with the directory then other info. Modify it if it is any use to you. Sean - -------START--------- #!/usr/bin/perl # # $Id: fb-rmold.pl,v 4.5 2000/01/28 22:01:05 mj Exp $ # # Delete Files over a certain age # # Copyright (C) 2000 Sean Rima $LIBDIR="/var/lib/fidogate"; ##### Options ################################################################ $time_old = time() - 3888000; $FILEAREA = "$LIBDIR/fareas.bbs"; ##### Configuration ########################################################## $total_global = 0; # Generate listing for one directory sub list_dir { local($dir) = @_; local($first,$file,$desc,@files,%files_dir); local($total) = 0; # Read contents of directory if(! opendir(DIR, $dir)) { print "--- area missing ---\r\n\r\n\r\n"; return 1; } @files = readdir(DIR); closedir(DIR); for $file (@files) { # ignore directories if( -d $file ) { next; } # ignore .* if( $file =~ /^\./ ) { next; } # ignore files.{bbs,bak,dat,dmp,idx} if( $file =~ /^files\.(bbs|bak|dat|dmp|idx|tr)$/ ) { next; } # ignore index.{dir,pag} if( $file =~ /^index\.(dir,pag)$/ ) { next; } $files_dir{$file} = 1; } # Read and print contents of files.bbs # if(open(FILES, "$dir/files.bbs")) { # while(<FILES>) { # s/\cM?\cJ$//; # # File entry # if( /^[a-zA-Z0-9]/ ) { # ($file, $desc) = split(' ', $_, 2); # $file =~ tr+A-Z\\+a-z/+; # $files_dir{$file} = 2; # $total += &list_file($dir, $file, $desc); # } # elsif( /^-:crlf/ ) { # next; # } # elsif(!$time_new) { # print $_,"\r\n"; # } # } # close(FILES); # } # else { # print "--- no files.bbs ---\r\n"; # } # Print files missing in files.bbs / add to files.bbs open(LOG, ">>/var/log/fidogate/fb-rmold") || die "filelist: can't open $dir/files.bbs\n"; for $file (sort keys(%files_dir)) { if($files_dir{$file} == 1) { if(open(FILES, "$dir/.desc/$file.desc")) { while(<FILES>) { $desc = $_; } close(FILES); } $total += &list_file($dir, $file, $desc); # printf FILES "%-12s %s\n", $file, $desc; } } $total_global += $total; # # print "\n"; } sub list_file { local($dir,$file,$desc) = @_; local($x,$size,$time); ($x,$x,$x,$x,$x,$x,$x, $size ,$x, $time ,$x,$x,$x) = stat("$dir/$file"); if($time_new && $time<$time_new) { return 0; } if($time>$time_old) { return 0; } unlink "$dir/$file"; unlink "$dir/.desc/$file.desc"; printf LOG "%s/%s deleted %s\n", $dir, $file, $size; return $size; } sub asctime { local($time) = @_; if($time eq "") { return " "; } else { local($yr, $mn, $dy, $h, $m, $s, $xx); ($s,$m,$h,$dy,$mn,$yr,$xx,$xx,$xx) = localtime($time); return sprintf("%02d.%02d.%02d", $dy,$mn+1,$yr-100, $h,$m); } } sub ksize{ local($size) = @_; local($k); if($size eq "") { return " N/A"; } else { if($size == 0) { $k = 0; } elsif($size <= 1024) { $k = 1; } else { $k = $size ; } return sprintf("%6d", $size); } } sub dump_file { local($file) = @_; open(F, "$file") || die "filelist: can't open $file\n"; while(<F>) { s/\cM?\cJ$//; next if( /^\cZ/ ); print $_,"\r\n"; } close(F); } ##### Main ##### # Read Maximus filearea.ctl open(F, "$FILEAREA") || die "filelist: can't open $FILEAREA\n"; <F> if(!$opt_f); # Ignore 1st line of fareas.bbs while(<F>) { s/\cM?\cJ$//; if($opt_f) { # Maximus filearea.ctl s/^\s*//; s/\s*$//; next if( /^%/ ); next if( /^$/ ); ($keyw,$args) = split(' ', $_, 2); $keyw =~ tr/[A-Z]/[a-z]/; if ($keyw eq "area" ) { $area = $args; } elsif($keyw eq "fileinfo") { $info = $args; } elsif($keyw eq "download") { $dir = $args; $dir =~ tr/[A-Z\\]/[a-z\/]/; $drv = substr($dir, 0, 2); $dir = substr($dir, 2, length($dir)-2); $dir = $dirs{$drv}.$dir; } elsif($keyw eq "end" ) { $args =~ tr/[A-Z]/[a-z]/; if($args eq "area") { $length = 50; if(length($info) > $length) { $info = substr($info, 0, $length); } $length -= length($info); printf "### MAX file area \#%-3d ### ", $area; print $info, " ", "#" x $length, "\r\n"; print "\r\n"; &list_dir($dir); } } } else { # FIDOGATE fareas.bbs ($dir,$area) = split(' ', $_); $dir =~ s/^\#//; if( $area =~ /^IREX\.(DOS|LNX|OS2|WIN)$/ ) { next; } if( $area =~ /^SUSE_RPM$/ ) { next; } if(! $dir_visited{$dir}) { $dir_visited{$dir} = 1; # $header = "### File area $area ###"; # $length = 78 - length($header); # print "$header", "#" x $length, "\r\n\r\n"; &list_dir($dir); } } close(LOG); } close(F); - ------END------ -- GNUPG ID 92B9D0CF | Fidonet: 2:263/950 ICQ: 679813 | Homepage: http://www.tcob1.net Linux User: #124682 | My last power cut was 0d, 3h and 7m ago ...What's a new brides' wedding night dread? Microsoft. <Gateway Information> Please do not respond direct to this message as the author will not see it This list is gated to a Fidonet Echo by tcob1 (http://www.tcob1.net)