nginx访问日志定时日志切割

日志切割脚本:
[root@lb-nginx logs]# cat /data/scripts/cut_nginxlog.sh
#!/bin/sh
#Dateformat=date +%Y%m%d
Dateformat=(date+Basedir="/aliyun/nginx"Nginxlogdir="(date +%F) Basedir="/aliyun/nginx" Nginxlogdir="Basedir/logs"
Logname=“access.log”
[ -d $Nginxlogdir ] && cd $Nginxlogdir||exit 1
[ -f ${Logname} ]||exit 1
/bin/mv ${Logname} {Dateformat}_Logname
$Basedir/sbin/nginx -s reload
#del 5 days ago logs
find $Basedir/logs/ -type f -name “*_access.Log” -mtime +5|xargs rm -f

写入定时任务:
[root@lb-nginx logs]# crontab -l
######cut ngx_access.logs####by wujianwei 2016-5-18
00 00 * * * /bin/sh /data/scripts/cut_nginxlog.sh &>/dev/null

posted @ 2018-01-01 22:01  勤奋的蓝猫  阅读(2)  评论(0编辑  收藏  举报  来源