Hi All Monks, I'm a Perl newbie who needs to be enlightened. I've been trying to put up some Perl code which tries to perform the following steps on a linux filesystem which contains zipped logfiles in this format:
logfile_22102008_1051.txt.gz
1.Check if the filesystem is filling up for over 10G
2.If the filesystem size is > 10G, delete the "oldest-day" ones.
3.If after this step the filesystem is still over 10G, delete the "oldest day" ones again and so on until we get under the 10G threshold.
In this last case just exit.
Here's my code snippet, please note that i didn't follow any perl books until now, i just tried to do my best with the notions i have collected on the web until now:
--
my $LOGSIZE = `du -s $LOGSTR | /bin/awk '{print \$1}'`; chomp( $LOGSTR + ); my $I = 5; my $S; # Up to 10G while ( $LOGSIZE > 10000000 && $I >= -1 ) { if ( $I <= -1 ) { $S = ""; } else { $S = "+"; } my $LOGSIZE = `du -s $LOGSTR | /bin/awk '{print \$1}'`; chomp( + $LOGSTR ); `/usr/bin/find $LOGSTR -name "*.gz" -print -mtime $S$I -exec r +m \{\} \\\;`; sleep 2; $I--; } ---
The sizes of the files are the same but the number of them may vary a lot. At this point my question is, since my code doesn't seem to work (it deletes all my .gz files) , how can i delete the "oldest day" files during every step of the filesystem size check? Is this the best solution? I have to keep the filesystem almost full to retain as much info as possible, but i need necessarily to delete the oldest ones because information arrives continously. I hope my explanation is clear enough; Thx Francesco

In reply to Deleting Oldest Logfiles by longjohnsilver

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.