nginx日志切割脚本

#!/bin/bash

ip=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`

desHost=10.124.156.244

Date_yestoday=`date -d "-1 day" +%Y%m%d`
#设置日志文件存放目录
logs_path="/usr/local/nginx/logs/"
#设置pid文件
pid_path="/usr/local/nginx/logs/nginx.pid"
if [[ ${ip} == '10.124.194.252' ]]; then
#log_cut
mv ${logs_path}access.log ${logs_path}/log_bak/nginx1_access_${date_yestoday}.log
mv ${logs_path}error.log ${logs_path}/log_bak/nginx2_error_${date_yestoday}.log
#向nginx主进程发信号重新打开日志
kill -USR1 `cat ${pid_path}`
#10天以前的日志删除
find /usr/local/nginx/logs/log_bak -ctime +10 -name "nginx1_access_201[0-9]*" | xargs rm -f
find /usr/local/nginx/logs/log_bak -ctime +10 -name "nginx1_error_201[0-9]*" | xargs rm -f
elif [[ ${ip} == '10.124.194.250' ]]; then
#重命名日志文件
mv ${logs_path}access.log ${logs_path}/log_bak/nginx2_access_${date_yestoday}.log
mv ${logs_path}error.log ${logs_path}/log_bak/nginx2_error_${date_yestoday}.log
#向nginx主进程发信号重新打开日志
kill -USR1 `cat ${pid_path}`

#10天以前的日志删除
find /usr/local/nginx/logs/log_bak -ctime +10 -name "nginx2_access_201[0-9]*" | xargs rm -f
find /usr/local/nginx/logs/log_bak -ctime +10 -name "nginx2_error_201[0-9]*" | xargs rm -f

上一篇:nginx 日志切割脚本


下一篇:linux shell:nginx日志切割脚本