常用指令碼

foreverfriends發表於2017-04-18
一、編寫定時切割nginx日誌指令碼
指令碼名稱:/usr/local/nginx/sbin/cut_nginx_log.sh
指令碼內容:
#!/bin/bash
#this script run at 00:00
#the nginx logs path
logs_path="/usr/local/nginx/logs"

mkdir -p ${logs_path}$(date  -d "yesterday"  +"%Y")/$(date -d  "yesterday")+"%m"
)/   mv  ${logs_path}access.log ${logs_path}$(date -d "yesterday"  +"%Y")/$(date -d "yesterday" + "%m")/access_$(date -d "yesterday" +"%Y%m%d").log
 kill -USR1 `cat /usr/local/nginx/nginx.pid`

設定crontab,每天凌晨切割nginx訪問日誌
00 00 * * *  /bin/bash   /usr/local/nginx/sbin/cut_nginx_log.sh

二、

相關文章