#!/bin/bash

logs_path="/home/wwwlogs/"
backdir="/home/wwwlogs/"

mkdir -p ${backdir}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/


for file in access.log accesstest.log access.log gt_access.log

do

  mv ${logs_path}$file ${backdir}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/`echo $file|awk -F '.'  '{ print $1}'`_$(date -d "yesterday" +"%Y%m%d").log

done

kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)

把脚本写入定时任务

01 00  * * * /data/script/cut_nginx_log.sh >/dev/null 2>&1