nginx日志切割
日志切割
#!/bin/bash #设置日志文件存放目录 logs_path="/home/centos/logs/" #设置pid文件 pid_path="/home/centos/logs/nginx.pid" #重命名日志文件 mv ${logs_path}access.log ${logs_path}access_$(date -d "yesterday" +"%Y%m%d").log #向nginx主进程发信号重新打开日志 kill -USR1 `cat ${pid_path}`
#!/bin/bash LISTENLIST=(1935 1936 1937 1938 1939 1940) now=`date +%s` let vnow=$now-60 bTime=`date -d @$vnow +%Y_%m_%d_%H` echo $bTime for data in ${LISTENLIST[@]} do dir=/var/trsslogs/nginx${data}/logbaks/rtmp_$bTime/ mkdir -p $dir cd /var/trsslogs/nginx${data} mv access.log common_access.log error.log full_access.log rtmp_access.log $dir done ps -ef|grep "nginx: master process ./nginx" |grep -v grep|awk '{print$2}' |xargs kill -USR1