在進行編寫指令碼之前,先進行以下假設: 日誌檔案是:/usr/local/nginx/logs/access.log nginx主程序id儲存在檔案:/usr/local/nginx/logs/nginx.pid 切割後備份檔案目錄:/usr/local/nginx/logs/bak/ 切割詳細步驟,請參閱下面操作:
1、建立檔案cut_access_log.sh: vim /.bin/cut_access_log.sh vim /.bin/cut_access_log.sh
2、輸入檔案cut_access_log.sh內容 #! /bin/bash org_path="/usr/local/nginx/logs/" dest_path="/usr/local/nginx/logs/bak/" if [ ! -d "$dest_path" ]; then mkdir "$dest_path"fimv ${org_path}access.log ${dest_path}access$(date +%Y%m%d).log kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
3、儲存cut_access_log.sh之後,賦可執行許可權 chmod +x /.bin/cut_access_log.sh
4、編寫crontab檔案:vim /.cron5、輸入crontab檔案內容,並保持 59 23 * * * /bin/bash /.bin/cut_access_log.sh 6、新增到crontab中
在進行編寫指令碼之前,先進行以下假設: 日誌檔案是:/usr/local/nginx/logs/access.log nginx主程序id儲存在檔案:/usr/local/nginx/logs/nginx.pid 切割後備份檔案目錄:/usr/local/nginx/logs/bak/ 切割詳細步驟,請參閱下面操作:
1、建立檔案cut_access_log.sh: vim /.bin/cut_access_log.sh vim /.bin/cut_access_log.sh
2、輸入檔案cut_access_log.sh內容 #! /bin/bash org_path="/usr/local/nginx/logs/" dest_path="/usr/local/nginx/logs/bak/" if [ ! -d "$dest_path" ]; then mkdir "$dest_path"fimv ${org_path}access.log ${dest_path}access$(date +%Y%m%d).log kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
3、儲存cut_access_log.sh之後,賦可執行許可權 chmod +x /.bin/cut_access_log.sh
4、編寫crontab檔案:vim /.cron5、輸入crontab檔案內容,並保持 59 23 * * * /bin/bash /.bin/cut_access_log.sh 6、新增到crontab中