Table of Contents

Log Rotation script

Short of using logrotate, below is a quick and simple script to do the same.

Script

Example of haproxy log rotation

#!/bin/bash
#
LOGDIR=/var/log
LOGFILE=haproxy.log
TARDIR=/data/log
#
LOGDIRFILE=${LOGDIR}/${LOGFILE}
cp $LOGDIRFILE ${TARDIR}/${LOGFILE}.`date +%Y%m%d_%H%M%S`
cat /dev/null > $LOGDIRFILE
exit

crontab entry

Include this /etc/crontab

00 00 * * * root /var/log/logroll