#! /bin/bash
nginx=/usr/local/nginx/sbin/nginx #NGINX的位置
Date=$(date -d -1day +"%Y%m%d") #获取昨天日期
logs_dir=/var/logs/ #log目录
bak_dir=/var/logs/$Date #log备份目录
#创建今日备份目录
mkdir $bak_dir
#先把现有的log文件挪到备份目录临时存放
cd $logs_dir
echo "moving logs"
/bin/mv *.log $bak_dir
sleep 3
#重建nginx log
echo "rebuild logs"
echo "nginx -s reopen"
$nginx -s reopen