您的位置:首页 > 运维架构 > Shell

nginx日志按天切割shell

2017-09-22 11:16 309 查看
#!/bin/bash
##############################################
#Author: Liuzhengwei - 1135960569@qq.com
#QQ:1135960569
#Last modified: 2017-08-16 16:05
#Filename: nginx_logrotate.sh
#Description:
##############################################
back_dir=/data/nginx_log
year=`date '+%Y'`
month=`date '+%m'`
if [ ! -d $back_dir/$year ];then
mkdir $back_dir/$year
if [ ! -d $back_dir/$year/$month ];then
mkdir $back_dir/$year/$month
fi
fi
cp $back_dir/access.log $back_dir/$year/$month
cp $back_dir/error.log $back_dir/$year/$month
cd $back_dir/$year/$month
gzip -c access.log > access.log_`(date '+%F')`.gz
gzip -c error.log > error.log_`(date '+%F')`.gz
find ./ -maxdepth 1 -name "*.log" | xargs rm -f
>$back_dir/access.log
>$back_dir/error.log
任务计划:
59 23 * * * /server/scripts/nginx_logrotate.sh &> /dev/null
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  日志 nginx 切割