1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #!C:/Perl/bin/perl.exe -w
#
#
# Parametres du script
$retention = 4;
$log_folder= 'c:/dev/perl/LOG';
$file_genname = 'DailyMpgateway';
system "echo %date% %time%" ;
open(LOGFILE, ">LOG.log");
# Print informations about the environnement
print "\n \n \n";
$machine = Win32::NodeName;
print "Script start on: $machine \n";
($string, $major, $minor, $build, $id) = Win32::GetOSVersion();
@os = qw(Win32s, Win95, WinNT);
print "With OS Version : $os[$id] $major\.$minor $string (Build $build)\n";
# Print the directoy where the perl script start;
$currpath = Win32::GetCwd();
print "Cuurent directory is $currpath \n";
# Changing directory and printing the current folder
chdir("$log_folder") || die "cannot cd to $log_folder ($!)";
$currpath = Win32::GetCwd();
print "Successfully changed to folder: $currpath \n \n \n";
# Displaying logfiles present in the directory
@all_logs = glob("$file_genname.log.*");
print "List of Logs present on folder: \n";
foreach (@all_logs) {
next unless -f;
next unless -r;
$age = -M;
print "Log: $_ Date: $age \n";
}
# Dispaying and deleting files older than $retention
print "\n \n";
opendir(DIR,'.') or die "$!";
my @logs_todelete = grep(/^$file_genname\.log\./ && int -M > $retention, readdir DIR);
close(DIR);
print "Files to be deleted:\n";
print "$_\n" for @logs_todelete;
# unlike $_ ;
#---------------------------------------- |
Partager