ah yeah makes sense now thanks :D , my mate said to say your the shiz!! lol
I looked up your -d and also found the -T which i am useing as i am only dealing with text files,
so i do this now to avoid directory's:
if ( -T $currentlog ) #checks wether the file is a text f
+ile
{
open(CURRENTLOG, $currentlog)|| die "file not found: $!";
}
else . . .
However i am now getting the error
"Permission denied at tempCHRONO.pl line 76, <CURRENTLOG> line 1"
on the code
$oldlocation = "/perl/ass/$logfiles[$hour]"; #Cut and Pastes
+ the log file into corresponding folder
$newlocation = "/perl/ass/$folder[$N]/$logfiles[$hour]";
print " old = $oldlocation \n new = $newlocation\n";
move($oldlocation, $newlocation) or die "File cannot be mo
+ved: $!";
I didnt really wanna post all my code as that is not me solving the error myself at all but if it helps :
#!/usr/bin/perl
use Date::EzDate; #Requests to use the
+date mod
use File::Copy;
my $currentdate = Date::EzDate->new(); #Loads the current Da
+te an Time
#
#Manageing Log Files Chronologically
#
my $hour = 2;
until ($hour > 26) #Loo
+p to read all log files
{
my $dateloaded = Date::EzDate->new(); #tak
+es todays date
opendir(LOGS, "/perl/ass/")|| die "dir not found"; #Ope
+ns the folder containing the days log files
my @logfiles = readdir(LOGS); #Put
+s the name of all files into an array
closedir(LOGS);
my $currentlog = "/perl/ass/$logfiles[$hour]";
if ( -T $currentlog ) #checks wether the file is a tex
+t file
{
open(CURRENTLOG, $currentlog)|| die "file not found: $!";
}
else
{
$hour++;
}
$firstline = <CURRENTLOG>;
$date = substr($firstline,0,2); #Ta
+ke the day of month from the log
$date2 = substr($firstline,3 ,2); #Ta
+kes the month from the log
$today = $currentdate->{'{day of month}'}; #To
+days Date
$month = $currentdate->{'month number'} +1; #To
+days Month
$dateloaded -= 7; #mi
+nus a week
$history = substr($dateloaded,8 ,2); #1-
+week-ago
$dateloaded -= 7; #fo
+r the whole week
$historyformer = substr($dateloaded,8 ,2); #En
+d 1-week-ago
$N = 0;
until ( $N == 3) #Un
+til all 3 weeks have been checked
{
@folder = qw( 1-week-ago 2-weeks-ago 3-week-ago );
if ( $date >= $historyformer && $date <= $history ) #if
+ the log equals greater than a week ago but less than 2 weeks ago
{
$month--;
if ( $date2 == $month || $date2 == $month )
{
$oldlocation = "/perl/ass/$logfiles[$hour]"; #Cu
+t and Pastes the log file into corresponding folder
$newlocation = "/perl/ass/$folder[$N]/$logfiles[$hour]";
print " old = $oldlocation \n new = $newlocation\n";
move($oldlocation, $newlocation) or die "File cannot be mo
+ved: $!"; #DOESNT WORK
$N = 3;
$date = 999; #Ma
+kes the date not equal to any other date
$month++;
}
}
$N++;
$history = substr($dateloaded,8 ,2);
$dateloaded -= 7;
$historyformer = substr($dateloaded,8 ,2); #En
+d 1-week-ago
}
$date = substr($firstline,3 ,2); #Co
+llect the month from the log
$N = 0;
until ( $N == 6) #Un
+til all 6 months have been checked
{
@folder = qw( 1-month-ago 2-months-ago 3-months-ago 4-months
+-ago 5-months-ago 6-months-ago);
$month--; #C
+ounts down 6 months
if ( $date == $month ) #i
+f the first line of the log equals the date
{
$oldlocation = "/perl/ass/$logfiles[$hour]"; #C
+ut and Pastes the log file into corresponding folder
$newlocation = "/perl/ass/$folder[$N]/$logfiles[$hour]";
print " OLD - $oldlocation \n NEW - $newlocation";
move($oldlocation, $newlocation) or die "File cannot be mo
+ved: $!"; #DOESNT WORK
$N = 3;
$date = 999; #M
+akes the date not equal to any other date
}
$N++;
}
#if ($date == $month -1)
# {
# DELETE;
# }
$hour++;
}
exit;
And no laughing because it isnt exactly finished :P |