vi /opt/sh/nginx_cut_logs.sh
1 #!/bin/bash 2 #设置日志文件存放目录 3 logs_path="/data/logs/" 4 #设置pid文件 5 pid_path="/opt/app/nginx/logs/nginx.pid" 6 7 new_logs_path="/log/nginx/" 8 9 files=`ls /data/logs/` 10 #重命名日志文件 11 for file in $files 12 do 13 mv ${logs_path}${file} ${new_logs_path}${file}_$(date -d "yesterday" +"%Y%m%d") 14 #echo ${logs_path}${file} ${new_logs_path}${file}_$(date -d "yesterday" +"%Y%m%d") 15 done 16 #向nginx主进程发信号重新打开日志 17 kill -USR1 `cat ${pid_path}`