5:49:24 hancock6@server4 /home/hancock6# cd logs 5:49:28 hancock6@server4 /home/hancock6/logs# ls 20020305.tar.gz 20020324.tar.gz 20020412.tar.gz 20020501.tar.gz 20020306.tar.gz 20020325.tar.gz 20020413.tar.gz 20020502.tar.gz 20020307.tar.gz 20020326.tar.gz 20020414.tar.gz 20020503.tar.gz 20020308.tar.gz 20020327.tar.gz 20020415.tar.gz 20020504.tar.gz 20020309.tar.gz 20020328.tar.gz 20020416.tar.gz 20020505.tar.gz 20020310.tar.gz 20020329.tar.gz 20020417.tar.gz 20020506.tar.gz 20020311.tar.gz 20020330.tar.gz 20020418.tar.gz 20020507.tar.gz 20020312.tar.gz 20020331.tar.gz 20020419.tar.gz 20020508.tar.gz 20020313.tar.gz 20020401.tar.gz 20020420.tar.gz 20020509.tar.gz 20020314.tar.gz 20020402.tar.gz 20020421.tar.gz 20020510.tar.gz 20020315.tar.gz 20020403.tar.gz 20020422.tar.gz 20020511.tar.gz 20020316.tar.gz 20020404.tar.gz 20020423.tar.gz 20020512.tar.gz 20020317.tar.gz 20020405.tar.gz 20020424.tar.gz 20020513.tar.gz 20020318.tar.gz ... etc 5:49:29 hancock6@server4 /home/hancock6/logs# mvlog.pl 5:49:40 hancock6@server4 /home/hancock6/logs# ls -R .: 200203/ 200204/ 200205/ access_log error_log mvlog.pl* 200203: 20020305.tar.gz 20020312.tar.gz 20020319.tar.gz 20020326.tar.gz 20020306.tar.gz 20020313.tar.gz 20020320.tar.gz 20020327.tar.gz 20020307.tar.gz 20020314.tar.gz 20020321.tar.gz 20020328.tar.gz 20020308.tar.gz 20020315.tar.gz 20020322.tar.gz 20020329.tar.gz 20020309.tar.gz 20020316.tar.gz 20020323.tar.gz 20020330.tar.gz 20020310.tar.gz 20020317.tar.gz 20020324.tar.gz 20020331.tar.gz 20020311.tar.gz 20020318.tar.gz 20020325.tar.gz 200204: 20020401.tar.gz 20020409.tar.gz 20020417.tar.gz 20020425.tar.gz 20020402.tar.gz 20020410.tar.gz 20020418.tar.gz 20020426.tar.gz 20020403.tar.gz 20020411.tar.gz 20020419.tar.gz 20020427.tar.gz 20020404.tar.gz 20020412.tar.gz 20020420.tar.gz 20020428.tar.gz 20020405.tar.gz 20020413.tar.gz 20020421.tar.gz 20020429.tar.gz ... etc #### #!/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); }