例:

nginx日志切割脚本

nginxLog_cut.sh

#!/bin/bash
logs_path="/home/logs/NginxLog/"
DAYS=30
mv ${logs_path}www.apple-dina.com.acc.log  ${logs_path}history/acc_logs/www.apple-dina.com.acc_$(date -d "yesterday" +"%Y%m%d").log
mv ${logs_path}www.apple-dina.com.err.log  ${logs_path}history/err_logs/www.apple-dina.com.err_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
#find ${logs_path}history/acc_logs/  -name "www.apple-dina.com.acc_*" -type f -mtime +$DAYS -exec rm {} \;
find ${logs_path}history/err_logs/  -name "www.apple-dina.com.err_*" -type f -mtime +$DAYS -exec rm {} \;

添加定时任务

crontab -e 
0 0 * * * /shell/nginxLog_cut.sh



乐享:知识积累,快乐无限。