pbaumgar has asked for the wisdom of the Perl Monks concerning the following question:
#!/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: $!"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: moving old files
by Paladin (Vicar) on Apr 20, 2006 at 17:05 UTC | |
|
Re: moving old files
by rhesa (Vicar) on Apr 20, 2006 at 17:21 UTC | |
|
Re: moving old files
by davidrw (Prior) on Apr 20, 2006 at 20:04 UTC | |
|
Re: moving old files
by brd (Acolyte) on Apr 21, 2006 at 00:19 UTC | |
by superfrink (Curate) on Apr 21, 2006 at 01:59 UTC | |
by brd (Acolyte) on Apr 21, 2006 at 05:06 UTC | |
by pbaumgar (Acolyte) on May 17, 2006 at 19:33 UTC |