#!/usr/bin/perl -w use strict; use File::Copy; my $log_dir = "/etc/httpd/logs/2006"; my $archive_dir = "/etc/httpd/logs/archive"; #open logs directory and get files older than 24 hours opendir(LOGS, $log_dir) or die "Directory could not be opened: $!"; my @files = grep { -M "$log_dir/$_" > 1 } readdir(LOGS); closedir(LOGS) or die "Directory could not be closed: $!"; #check each file in logs directory my @to_move; foreach my $file (@files) { $file eq '.' || $file eq '..' or push @to_move, $file; } #perform file test; compress file; move file foreach my $file (@to_move) { if (! -l $file) { chdir $log_dir or die "Can't chdir to $log_dir: $!"; system "gzip $file"; move "$file.gz", $archive_dir; } else { die "Can't move $file: $!"; } }
In reply to moving old files by pbaumgar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |