Friends, I have a dab of perl that I use to dlt files older than 30 days from a given dir. I wish to enhance this so that a log of what was deleated -and when . I am unable to get the logging to work. the file for appending to as a log is /script_logs/30DyDlt.txt here is my perl --------------------------------------------------
###:WAS Oven1 = '/media/oven_web/iportal/uploads' # rvsd to oven2 - 4-2009 js # /oven_web/iportal/uploads # # to del files older than 30 days ### 2.28.2008 - js #!/usr/local/bin/perl # 2592000 = 30 day n min (60 *60 * 24 *30 ) use strict; use POSIX; # change the below to dlt - dl30 my $file = "/script_logs/30DyDlt.txt"; my $date = localtime(); my $dir = '/oven_web/iportal/cgi-bin/uploads'; opendir(DIR,$dir) || die "Can't open $dir : $!\n"; my @files = readdir(DIR); # you may want to grep only certain files he +re close(DIR); my $logmsg = $date/$dir/$file(@files); #my $logmsg = $date/$dir/$file; #print $logmsg = $date/$dir/$file; open FILE, ">> $logmsg " or die " cannot open logfie $logfile for appe +nd $!"; foreach my $file(@files) { my $now = time; my @stat = stat("$dir/$file"); if ($stat[9] < ($now - 2592000)) { print "Deleting $dir/$file..."; #unlink("$dir/$file"); #print "Done.\n"; print LOGFILE $logmsg, "\n"; } } close LOGFILE;
--------------------- I am unsure if I need the use POSIX; -- i read that might help ... it didn't Any assistance would be appreciated. I seem to not be declareing some vars properly Thanks!

In reply to how to log a process by Anonymous Monk

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.