JArner has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, I found a bit of code searching for a way to clean up an 80G log file that is eating up space on a server. I don't want to just erase everything, I would like to keep 6 months of history at least. Would you be able to help me understand this bit of code? And make it useful for this purpose?
perl -i.~ -MTime::Local -ane'BEGIN { @months{ qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ) } = 1 .. 12; ( $day, $month, $year ) = (localtime)[ 3 .. 5 ]; $my_dt = timelocal( 0, 0, 0, $day, $month, $year ) - 2 * 60 * 60 * 2 +4; } @dt = split /-/, $F[0]; print if timelocal( 0, 0, 0, $dt[0], $months{ $dt[1] } - 1, $dt[2] ) >= $my_dt ' logfile
The logfile has entries as follows...
Jan 26 03:41:14 tul-access-5-8 mgd[61746]: UI_CHILD_STATUS: Cleanup child '/usr/sbin/smid', PID 61756, status 0Any help in this matter would be greatly appreciated. -Jim
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Script to clean up a log file based on timestamps
by NetWallah (Canon) on Oct 29, 2014 at 00:42 UTC | |
by Anonymous Monk on Oct 29, 2014 at 07:55 UTC | |
|
Re: Script to clean up a log file based on timestamps
by Anonymous Monk on Oct 29, 2014 at 00:00 UTC | |
by Anonymous Monk on Oct 29, 2014 at 00:01 UTC |