#!/bin/bash
# This script run at 03:00
# split yesterday log and gzip the day before yesterday log files.
# yesterday logs to awstats
# Added by royoy
# The Nginx bin path
nginx_bin="/usr/local/nginx/sbin/nginx"
# The Nginx logs path
logs_path="/data/logs/"
date_dir=${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/$(date -d "yesterday" +"%d")/
gzip_date_dir=${logs_path}$(date -d "-2 day" +"%Y")/$(date -d "-2 day" +"%m")/$(date -d "-2 day" +"%d")/
if [ ! -d $date_dir ]
then
mkdir -p $date_dir
fi
mv ${logs_path}*.log $date_dir
[ -x $nginx_bin ] && $nginx_bin -s reopen || echo "Not find $nginx_bin, or nginx not installed" >> /var/log/cut_nginx.log
if [ -d $gzip_date_dir ]
then
/usr/bin/gzip ${gzip_date_dir}*.log
fi
#delete expires log
expires_log=${logs_path}$(date -d "90 day ago" +"%Y/%m/%d")
rm -rf $expires_log