On Tue, Apr 06, 2010 at 02:24:27PM +0200, frantisek holop wrote:
| my goal is to have log files that end at a certain period.
| 
| e.g. an archived log file of march that doesn't contain
| april entries (from the "future"), although it's all right
| if it contains a couple of stray entries from february
| (the casualties of log rotation).

Aren't those first few also the casualties of log rotation ? I don't
see what you gain here, honestly. Either you have the first log
entries of a month in the rotated logs of the previous month. Or you
have the last log entries of a month in the rotated logs of the next
month. Tomato vs tomato.

| now i have logfiles named after the current month containing
| all the entries from the previous month.

So rename your logs properly.

| getting the name of the previous month from the current month
| is another can of worms i dont want to open.

What, really ?!

The approach with a simple lookup table:

PREVMONTH[1]="dec"; PREVMONTH[2]="jan"; PREVMONTH[3]="feb"
PREVMONTH[4]="mar"; PREVMONTH[5]="apr"; PREVMONTH[6]="may"
PREVMONTH[7]="jun"; PREVMONTH[8]="jul"; PREVMONTH[9]="aug"
PREVMONTH[10]="sep"; PREVMONTH[11]="oct"; PREVMONTH[12]="nov"

echo ${PREVMONTH[`date +%m`]}

Or, if you are certain you're within the first day of the new month
(as for 0 0 1 * * crons), `date -r $(($(date +%s) - 24*3600)) +%m`
(adjust for 'first week of new month' etc .. or get fancy and find the
number of days you've spent in the current month and go back that many
plus one).

Come on man .. 'can of worms' ?! It's not even a real challenge.

Paul 'WEiRD' de Weerd

-- 
>++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
+++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
                 http://www.weirdnet.nl/                 

Reply via email to