Hope this gives an idea of what it does! It's pretty much hardwired to what I needed it to do as well (as in name formats for the files/dirs to create), but maybe someone might find it of use :)
#!/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);
}