shell 按天自动割裂nginx日志,清理7天前日志文件

来源:互联网 发布:网络举报工作 编辑:程序博客网 时间:2024/05/16 09:53
#!/bin/sh


LANG=C
LC_ALL=C
PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/bin:/bin:/usr/local/bin"
export LANG LC_ALL PATH


NGINXPID=/usr/local/nginx/pid/nginx.pid


#log dir


D=`date -d  '-1 day' +%Y%m%d`
DEL=`date -d  '-7 day' +%Y%m%d`


for log in `ls  /usr/local/nginx/logs/ | egrep "log$"`
do
/bin/mv /usr/local/nginx/logs/$log /usr/local/nginx/logs/$log.$D
/bin/rm /usr/local/nginx/logs/$log.$DEL
done
# fflush nginx log 
kill -USR1 `cat $NGINXPID`
0 0
原创粉丝点击