PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Apache und Logfiles



27.07.00, 15:28
HiHo !!!

Ich habe mehrere virtuelle Domains, für die
alle einzelne transfer und errorlogs angelegt werden.

Nun naht das Ende des Monats und ich würde es gerne
sehen, dass die Logfiles am Ende des Monats "gepackt"
und in ihrem Verzeichnis verbleiben; und danach wieder
ein neues Logfile angelegt wird.

Gehört habe ich von "rotatelogs"...Wie binde ich diese
denn nun in meine Suse6.4 standard installation ein ?

modernart
27.07.00, 15:36
Hallo,

versuche es mal hiermit:




#!/bin/sh
################################################## ############################
## ##
## This reads a list of logfiles from $ROTATEME in $LOGDIR to rotate. ##
## Run it weekly and you'll have old logs for a month or so. ##
## ##
## The $ROTATEME file should have one log name per line. ##
## ##
## I thought the old .0, .1, .2 scheme was lame, so this will result in ##
## logs named foo.dusty, foo.moldy, foo.rotting, and foo.unholy. If you ##
## want more than 4 iterations, try adding .grimey and .pungent, or ##
## maybe .putrid. ##
## ##
## The idea came from necessity and Essential System Administration ##
## ("the red book"), but I, Matt Laney, take most of the ##
## credit. Bwah-hah-hah! (It's the little things we're proud of. http://www.linuxforen.de/ubb/wink.gif ##
## ##
## mlaney@exeter.org ##
## 1jh43 ##
## ##
## Get yours at http://www.exeter.org/~matt/software. ##
## ##
## rights: Berkeley-style (just use it, but keep my name with it) ##
## ##
################################################## ############################

LOGDIR=/var/log

OLD=$LOGDIR/OldLogs

ROTATEME=$LOGDIR/.rotateme

PID=/etc/syslog.pid

# change to the log directory
cd $LOGDIR

# just so we know when it last ran
touch .last-rotated

# make sure we have a directory to which to send these
if [ ! -d $OLD ]; then
mkdir -m 755 $OLD
fi

while read LOGFILE JUNK
do

# squish anything that got unsquished in the $OLD directory
gzip -9 -f $OLD/$LOGFILE.moldy $OLD/$LOGFILE.dusty $OLD/$LOGFILE.rotting $OLD/$LOGFILE.unholy > /dev/null 2>&1

# move them all one notch down the scale
if [ -r $OLD/$LOGFILE.rotting.gz ]; then
mv -f $OLD/$LOGFILE.rotting.gz $OLD/$LOGFILE.unholy.gz
fi

if [ -r $OLD/$LOGFILE.moldy.gz ]; then
mv -f $OLD/$LOGFILE.moldy.gz $OLD/$LOGFILE.rotting.gz
fi

if [ -r $OLD/$LOGFILE.dusty.gz ]; then
mv -f $OLD/$LOGFILE.dusty.gz $OLD/$LOGFILE.moldy.gz
fi

# take care of the most recent
if [ -r $LOGFILE ]; then
cp -p $LOGFILE $OLD/$LOGFILE.dusty
gzip -9 $OLD/$LOGFILE.dusty
cat /dev/null > $LOGFILE
fi

done <$ROTATEME


# this restarts syslogd, which is a vital step
# if you have something BSDish, you might prefer 'killall -HUP syslogd'
# if you have something SysV-ish, you mightn't want to run 'killall' as root :-)

kill -HUP `head -1 $PID`



musst hat noch etwas anpassen, und dann in den crontab eintagen. Ich kopiere mir die Vorlagen immer nach /etc/skel

Dann brauch ich die nur noch etwas editieren.

Gruss