#!/bin/bash # # PHP日志切割 # logs_path="/data1/logs/apps/php" # 每分钟切割 tm=$(date +'%Y-%m-%d-%H-%M' -d '10 minutes ago') cd $logs_path || exit 1 cut_log() { logfile=$1 targetfile=$2 [ -f "$targetfile" ] && return 1 [ -f "$logfile" ] || return 1 [ $(stat -c %s $logfile) -eq 0 ] && return 1 mv $logfile $targetfile chown www:www $targetfile return 0 } cut_log www-access_log www-access_${tm}.log cut_log php-fpm_slow.log php-fpm_slow_${tm}.log /etc/init.d/php-fpm reloadlog #删除7天前的日志
find . -maxdepth 1 -mtime +7 -type f -exec rm {} \; exit 0