Log file rotation script

Dave Cheney dave at cheney.net
Mon Jun 9 06:07:23 MSD 2008


I wrote this a while ago which does the trick

#!/bin/bash

YEAR=`date "+%Y"`
MONTH=`date "+%m"`
DAY=`date "+%d"`

HOSTNAME=`hostname -s`

LOG_FILES="access.log error.log"

DATE=$YEAR/$MONTH/$DAY

LOG_ROOT=/var/log
NGINX_LOG_ROOT=$LOG_ROOT/nginx

# make path

mkdir -p $NGINX_LOG_ROOT/$DATE

# touch and symlink in new log files

for FILE in $LOG_FILES; do
	LOG_FILE=$NGINX_LOG_ROOT/$DATE/$HOSTNAME.$FILE
	touch $LOG_FILE
	ln -fs $LOG_FILE $NGINX_LOG_ROOT/$FILE
done

# tell nginx to re-open its log files

kill -USR1 `cat /var/run/nginx.pid`




On 09/06/2008, at 11:50 AM, Rt Ibmer wrote:

> Hi - does anyone have a log file rotation script for nginx they can  
> share? Basically just looking for something simple I can set up in  
> cron once a day that will tell nginx to roll the log file and set  
> its file name to the current date, and then gzip it.  Thanks!
>
>
>
>
>
>






More information about the nginx mailing list