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,

In reply to Re^2: Appending date to filename for Archiving by viperl
in thread Appending date to filename for Archiving by viperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.