I have a script that compares the mtime of a file with timelocal set back 24 hours.
If the mtime is less then the timelocal it removes the file.
I am trying to modify it so we have the option to save files whatever number of days back we would like.
The subroutine is below the way it is now it does not reduce the timelocal to less then previous day file's mtime.
How should I do the calculation so it reduces the timelocal back more then one day?
sub clean_up() { my ( $mtime ) = ( stat $_ )[9]; my $BACKUP_TIME = $params->get("Backup.Tape.Start"); my $SERVER = $params->get("Backup.Server"); my $SAVE_DAYS = 1; my $SAVE_DAYS = $params->get("Backup.Save.Days") if ( $params->exists( +"Backup.Save.Days") ); my ( $BACKUP_HOUR, $BACKUP_MIN ); if ( $BACKUP_TIME =~ /^\d{1,2}:\d{1,2}$/ ) { ( $BACKUP_HOUR, $BACKUP_MIN ) = split /:/, $BACKUP_TIME; } else { $app->log($WARN, "Parameter \"Backup.Tape.Start\" not formatted pr +operly [ HH:MM ]. Defaulting to 07:00"); ( $BACKUP_HOUR, $BACKUP_MIN ) = ( 07, 00 ); } my ($min, $hour, $mday, $month, $year ) = (localtime)[1,2,3,4,5]; my $time = timelocal(0,$BACKUP_MIN,$BACKUP_HOUR,$mday,$month,$year); ##Set time to yesterday if current time of day < configured back-up t +ime $time -= ((60 * 60) * (24 * $SAVE_DAYS)) if ( $hour < $BACKUP_HOUR || ( $hour == $BACKUP_HOUR && $min < $BA +CKUP_MIN )); if ( $mtime < $time ){ print "$_\n"; } #unlink $_ if ( $mtime < $time ); }

In reply to Setting timelocal back by days by mnlight

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.