in reply to Re: Appending date to filename for Archiving
in thread Appending date to filename for Archiving

Hi Guys, I tried using your recommendation. I get the following errors.
Subroutine main::ctime redefined at /usr/lib/perl5/5.8.5/Exporter.pm line 65. at bstpcleanup.pl line 8 Prototype mismatch: sub main::ctime: none vs (;$) at /usr/lib/perl5/5.8.5/Exporter.pm line 65. at bstpcleanup.pl line 8 Unquoted string "age" may clash with future reserved word
#!/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); }
I think I am not using POSIX correctly. Can you help. Thanks,

Replies are listed 'Best First'.
Re^3: Appending date to filename for Archiving
by viperl (Initiate) on Jul 06, 2009 at 06:52 UTC
    Hi All, Can you help me with the above usage of POSIX. Thank you,