I think I am not using POSIX correctly. Can you help. Thanks,#!/usr/bin/perl -w use POSIX; use POSIX qw(strftime); use File::stat; use Time::localtime; $main::logFolder = "/apps/live/mail/logs"; $main::Folder = "/apps/live/mail/files/Archive"; print ctime()." :Start of File Cleanup\n"; $ClientName = 'abacs'; # Deleting Files that are older than 14 days chdir $main::Folder or die "can't cd"; foreach (glob("*")) { $age = -M; if ($age > 14) { Logit ( "$_ is over 14 days old" ); print "Deleting $_ " ; unlink $_; } else { Logit("$_ is ",int($age)," days old"); } } # Renaming the t-1 day log file and deleting log files older than 14 d +ays chdir $main::logFolder or die "can't cd"; foreach (glob("*")) { my $file_date = POSIX::strftime '%Y%m%d', localtime( ( stat )[ 9 ]+ ) +; $age = -M; if ($age>=1 && age < 2) { #rename Log File to .log.yyyymmdd rename ($_, $_ .$file_date" } else if($age > 14) { unlink $_; } } sub Logit{ my $message = shift(@_); if ($message =~ /^ERROR.*/){ print "ERROR"; } open (LOGF, '>>',$main::logFile); if (-w LOGF){ print LOGF ctime(). " $ClientName $message\n"; } else { print "Cannot open $main::logFile for writing, $!\n"; } close (LOGF); }
In reply to Re^2: Appending date to filename for Archiving
by viperl
in thread Appending date to filename for Archiving
by viperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |