$hrs = 72; #number of hours to keep in the logs $mydir = "webvert"; $baseref = "/home/web/glamazon/cgi-bin/$mydir"; $logs_dir = $baseref ."/logs"; $adbanners = $baseref ."/adcount.txt"; $numdate = time(); $cutoff = $numdate - ($hrs * 3600); open (BANNERS, "<$adbanners"); seek BANNERS, 0,0; @bannernames = ; close BANNERS; pop @bannernames; foreach $line (@bannernames) { chop ($line) if ($line =~ /\n$/); &trimlog($line); } sub trimlog { # trims logs to preset cutoff local ($filename) = @_; $logfile = "$logs_dir/$filename.log"; if (-e $logfile) { # Read through the log, looking for another hit print "Trimming $logfile\n"; open (LOG, "<" . $logfile); seek LOG, 0, 0; @loglines = ; close LOG; open (LOG, ">" . $logfile); foreach $line ( @loglines ) { ($my_ip, $my_time, $my_referer ) = split(/ /,$line); if ($my_time > $cutoff) {print LOG "$line";} } close LOG; } else { print "Cannot find $logfile\n"; } }