1#!/usr/bin/perl 2# 3# dead areas checker 4# by roman korolyov 5# rk@inetcomm.net / 2:5095/1.0 6# 7$DUPES="/home/fido/dupes/*.dph"; # filemask to dupebase 8$EXCLUDE="/home/fido/config/deadareas.exclude"; #Exclude areas 9$DEADTIME=30; # days before set to dead 10$LOGFILE="/home/fido/log/deadareas.log";# logfile 11$DEADFILE="/home/fido/log/dead.areas"; 12 13@month=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); 14 15open(EXCL,"$EXCLUDE"); 16while(<EXCL>) { 17 chomp; 18 $EXCAREA{lc($_)}=1; 19} 20close (EXCL); 21 22open(LOG,">>$LOGFILE"); 23open(DEADF,">$DEADFILE"); 24 25@dps=< $DUPES >; 26$curtime=time; 27 28 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); 29 if ( length($mday) < 2 ) { $mday="0".$mday; } 30 if ( length($hour) < 2 ) { $hour="0".$hour; } 31 if ( length($min) < 2 ) { $min ="0".$min ; } 32 if ( length($sec) < 2 ) { $sec ="0".$sec ; } 33 $logtime="$hour:$min:$sec $mday-$month[$mon]-".(1900+$year); 34 35 print LOG "--- $logtime ---\n"; 36 foreach $i ( @dps ) { 37 if ( length($i) > 1 ) { 38 39($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($i); 40 $i=~m/\/(.+)\/(.+)\.dph/g; 41 $fname=$2; 42 if ( $curtime >= $mtime ) { 43 if ( ( $curtime - $mtime ) > ($DEADTIME*24*60*60) ) { 44 if ( $EXCAREA{lc($fname)} != 1 ) { 45 print LOG uc($fname)," dead for ",int(($curtime - $mtime)/60/60/24)," days\n"; 46 print DEADF uc($fname)," ",int(($curtime - $mtime)/60/60/24),"\n"; 47 } 48 } 49 50 } else { 51 print LOG uc($fname)," has future time\n"; 52 } 53 } 54 } 55 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); 56 if ( length($mday) < 2 ) { $mday="0".$mday; } 57 if ( length($hour) < 2 ) { $hour="0".$hour; } 58 if ( length($min) < 2 ) { $min ="0".$min ; } 59 if ( length($sec) < 2 ) { $sec ="0".$sec ; } 60 $logtime="$hour:$min:$sec $mday-$month[$mon]-".(1900+$year); 61 62 print LOG "--- $logtime ---\n"; 63 64close (LOG); 65close (DEADF); 66