vi /opt/sh/nginx_cut_logs.shnginx
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}`