Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.mel.connect.com.au!news.mel.aone.net.au!grumpy.fl.net.au!news.webspan.net!www.nntp.primenet.com!nntp.primenet.com!mr.net!newsfeeds.sol.net!news-xfer.netaxs.com!news.mathworks.com!newsfeed.internetmci.com!demos!news1.best.com!nntp1.best.com!shellx.best.com!not-for-mail From: csuley@best.com (Christopher Suley) Newsgroups: comp.unix.bsd.freebsd.misc Subject: Re: Newbie: Rotating logfile monthly Date: 9 Jan 1997 20:57:16 -0800 Organization: the breaking of small, important bones Lines: 43 Message-ID: <5b4i7c$4ft@shellx.best.com> References: <5ah9su$bsk@eve.enteract.com> NNTP-Posting-Host: shellx.best.com Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:33832 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. Here's a quick sh script I hacked up to rotate the Apache logs on our FreeBSD box. As the header comment and coding style show, I'm not a Unix or sh guru, but this seems to work for me. #!/bin/sh # Rotate www logs. DON'T RUN THIS IF YOU AREN'T ROOT. IT WON'T WORK. cd /home/web/www/server/logs/ today=`date "+%m%d%y"` if ( test -f access_log ) then if ( test -f error_log ) then mv access_log access_log.$today ; \ mv error_log error_log.$today ; \ kill -1 `cat httpd.pid` else mv access_log access_log.$today ; \ kill -1 `cat httpd.pid` fi else if ( test -f error_log ) then mv error_log error_log.$today ; \ kill -1 `cat httpd.pid` fi fi if ( test -f access_log.$today ) then gzip access_log.$today chown web access_log.$today.gz fi if ( test -f error_log.$today ) then gzip error_log.$today chown web error_log.$today.gz fi Hope this helps! -- Christopher Suley - Got a Mac? Try Zipple: ftp://ftp.best.com/pub/csuley csuley@best.com - csuley@netcom.com - AOL and eWorld: ChrisSuley