#!/bin/bash # # Nginx 日志切割 # logs_path='/data1/logs/apps/nginx/' # 每分钟切割 tm=$(date +"%Y%m%d%H%M" -d "1 min ago") cd $logs_path || exit 1 for cate in 'access' 'error'; do for domain in $(ls *-{cate}_log |cut -d"-" -f1); do alog="$domain-${cate}_log" [ -f "$alog" ] || continue [ $(stat -c %s $alog) -eq 0 ] && continue [ -f "$domain-{cate}_${tm}.log" ] || mv $domain-{cate}_log $domain-${cate}_${tm}.log done done /etc/init.d/nginx reopen_logs #删除7天前的日志 find . -maxdepth 1 -mtime +7 -type f -exec rm {} \; exit 0