#!/bin/bash
#nginx logs incise script
#Global variable
LOG_DIR=/app/nginx/logs
DATE_FILE=access_`date +%Y-%m-%d`.log
ONE_MONTH_AGO=access_`date +%Y-%m-%d -d "1 month ago"`.log
#Logs reset
mv $LOG_DIR/access.log $LOG_DIR/$DATE_FILE
kill -USR1 `cat /app/nginx/logs/nginx.pid`
#Delete logs for one month ago
for ACCESS in `ls -l /app/nginx/logs/ | awk '{print $9}'`
do
if [ $ACCESS = $ONE_MONTH_AGO ]; then
rm -rf $LOG_DIR/$ONE_MONTH_AGO
fi
done
本文转自 走在右边 51CTO博客,原文链接:http://blog.51cto.com/gsliuyang/269392,如需转载请自行联系原作者