logrotate服务器操作及应用

通过logrotate配置nginx日志按天生成,及检测当日404请求

/usr/local/nginx/logs/*.log {
    daily
    dateext
    missingok
    rotate 7
    nocompress
    notifempty
    sharedscripts         
    postrotate
        if [ -f /usr/local/nginx/logs/nginx.pid ]; then
	    kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
	fi
	if ['grep -c "404" /usr/local/nginx/logs/access.log' -ne 0]; then
	    mail -s "nginx" 873720812@qq.com < /usr/local/nginx/logs/access.log
		awk '$9==404 {print $4,$5,$9,$7,$6}' /usr/local/nginx/logs/access.log | mail -s "nginx" 873720812@qq.com
	fi
	endscript
}

 

©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页