简单的 shell 脚本 切分日志
为避免日志过大,需要按天分割日志,定时计划任务脚本如下:
/data/shell/backup_yesterday_nginx_log.sh
declare logs_path="/data/log/nginx";
#declare need_delete_path=${logs_path}/$(date -d "7 days ago" "+%Y_%m_%d");
#declare yestoday_log_path=${logs_path}/$(date -d "yesterday" "+%Y_%m_%d");
declare yestoday_log_path=${logs_path}/$(date -d "yesterday" "+%w");
#rm -rf ${need_delete_path}
sudo rm -rf ${yestoday_log_path}
sudo mv ${logs_path}/today ${yestoday_log_path}
sudo mkdir -p ${logs_path}/today
sudo /usr/local/nginx/sbin/nginx -s reload