*BSD News Article 86165


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!news-xfer.netaxs.com!news.mathworks.com!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news
From: j@uriah.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Newbie: Rotating logfile monthly
Date: 3 Jan 1997 21:40:42 GMT
Organization: Private BSD site, Dresden
Lines: 34
Message-ID: <5ajucq$fnk@uriah.heep.sax.de>
References: <5ah9su$bsk@eve.enteract.com>
Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
NNTP-Posting-Host: localhost.heep.sax.de
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: knews 0.9.6
X-Phone: +49-351-2012 669
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F  93 21 E0 7D F9 12 D6 4E
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:33582

Dannyman <dannyman@dannyland.org> wrote:

> Wanna rotate my Apache access_log, and other similiar such beasties,
> every month. Basically, rename the thing with the likes of
> access_log-[jan-dec]-1997, etc and maybe run compress on it.

Don't forget to send Apache a SIGHUP afterwards, or it will continue
filling the old log file.

> 	Now, what buggers me, are what are some cool ways to get a
> name of the current month, or the previous month, sitting in a
> script.

$ date +"digits: %m, abbrev: %b, full name: %B"
digits: 01, abbrev: Jan, full name: January

As for the previous month, it's a little more difficult.  There's no
standardized option to date(1) to have it spit out the date string for
an arbitrary point in time.  (GNU date is said to allow for it.)

$ mon=$(($(date +%m) - 1))
$ if [ $mon -eq 0 ] ; then
>         mon=12
> fi
$ mon=$(printf "%02d" $mon)
$ echo $mon
12

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)