#!/bin/bash
# This script run at 03:40
# split yesterday log and gzip the day before yesterday log files.
# delete the log of 15 days ago
# edited by royoy
logs_path="/data/logs/php/var/log/"
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
/etc/init.d/php-fpm reload
sleep 1
chmod a+r ${logs_path}*.log
if [ -d $gzip_date_dir ]
then
/usr/bin/gzip ${gzip_date_dir}*.log
fi
#delete expires log (15 days ago)
expires_log=${logs_path}$(date -d "15 day ago" +"%Y/%m/%d")
rm -rf $expires_log