#!/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