![]() |
|
laziness, impatience, and hubris | |
PerlMonks |
Log file backupby munk (Novice) |
on May 23, 2002 at 14:39 UTC ( #168774=snippet: print w/replies, xml ) | Need Help?? |
#!/usr/bin/perl # # move files from a log dir # into a newly created directory # based on the name of the logfiles # 20020305.tar.gz use strict; my (@logfiles); # file cntaining all the logfiles: my $logdir="/home/hancock6/logs"; #open the dir ready for reading: opendir(LOGDIR, $logdir); #read in files from dir: my @logdir=readdir(LOGDIR); for my $file (@logdir){ # foreach file in the dir, if it's a tarball, # copy it into @logfiles: if($file=~/(.*)\.tar\.gz$/){ push(@logfiles, $file); print $file,"\n"; } } for my $logfile (@logfiles){ # foreach logfile in @logfiles, # build the dirname to copy it to: $logfile=~/(.*)\.tar\.gz$/; my $dirname=substr($1,0,-2); $dirname=$logdir."/".$dirname; print $dirname,"\n"; # check if the dir exists, if not, create it: if(!-e $dirname){ mkdir($dirname, 0755); } # copy the file into the dir: link ($logdir."/".$logfile, $dirname."/".$logfile); # remover the old file: unlink($logdir."/".$logfile); }
|
|