#!/usr/bin/perl use Date::EzDate; #Requests to use the date mod use File::Copy; my $currentdate = Date::EzDate->new(); #Loads the current Date an Time # #Manageing Log Files Chronologically # my $hour = 2; until ($hour > 26) #Loop to read all log files { my $dateloaded = Date::EzDate->new(); #takes todays date opendir(LOGS, "/perl/ass/")|| die "dir not found"; #Opens the folder containing the days log files my @logfiles = readdir(LOGS); #Puts 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 text file { open(CURRENTLOG, $currentlog)|| die "file not found: $!"; } else { $hour++; } $firstline = ; $date = substr($firstline,0,2); #Take the day of month from the log $date2 = substr($firstline,3 ,2); #Takes the month from the log $today = $currentdate->{'{day of month}'}; #Todays Date $month = $currentdate->{'month number'} +1; #Todays Month $dateloaded -= 7; #minus a week $history = substr($dateloaded,8 ,2); #1-week-ago $dateloaded -= 7; #for the whole week $historyformer = substr($dateloaded,8 ,2); #End 1-week-ago $N = 0; until ( $N == 3) #Until 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]"; #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 moved: $!"; #DOESNT WORK $N = 3; $date = 999; #Makes the date not equal to any other date $month++; } } $N++; $history = substr($dateloaded,8 ,2); $dateloaded -= 7; $historyformer = substr($dateloaded,8 ,2); #End 1-week-ago } $date = substr($firstline,3 ,2); #Collect the month from the log $N = 0; until ( $N == 6) #Until 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--; #Counts down 6 months if ( $date == $month ) #if the first line of the log equals the date { $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"; move($oldlocation, $newlocation) or die "File cannot be moved: $!"; #DOESNT WORK $N = 3; $date = 999; #Makes the date not equal to any other date } $N++; } #if ($date == $month -1) # { # DELETE; # } $hour++; } exit;