nginx 日志切割脚本
#!/bin/bash #这个脚本是用来切割nginx日志 根据自己情况进行必要的切割: set -e logs_path="/data/wwwlogs/" oldlogs_path="/data/wwwlogs/ngx_oldlogs/" hos="ngx128" old_nginx=`mv ${logs_path}access.log ${logs_path}access_$(date -d "yesterday" +"%Y%m%d")_$hos.log` for i in `ls $logs_path/* | egrep -v "*.gz|log"` do mv "$i" "$i"_${hos}_$(date -d "yesterday" +"%Y%m%d") mv "$i"_${hos}_$(date -d "yesterday" +"%Y%m%d") $oldlogs_path done kill -USR1 $(cat /var/run/nginx/nginx.pid) #mv $old_nginx $oldlogs_path cd $old_nginx find ./ -mtime +30 -exec rm -rf {} \; sleep 1 echo "The old logfiles is deleted!!"
本文出自 “天真无邪” 博客,请务必保留此出处http://innocence.blog.51cto.com/4313888/1978817
原文地址:http://innocence.blog.51cto.com/4313888/1978817