时间:2021-07-01 10:21:17 帮助过:10人阅读
我这里是按时间拆,
#!/bin/bash #访问日志文件位置 nginx_path="/usr/local/nginx/logs/" bak_path="/usr/local/nginx/logs/dowload/" #本程序log位置 包含文件名 log_path="/usr/local/nginx/logs/mv_log.log" #文件夹名称英文逗号分隔 access_name="dir1,dir2,dir3,dir4,dir5,dir6" #nginx pid文件位置 nginx_pid_path="/usr/local/nginx/logs/nginx.pid" DATE=$(date +%Y-%m-%d ) log_time=$(date +%Y-%m-%d_%H:%M:%S) echo "time ${DATE}" echo $log_time OLD_IFS="$IFS" IFS="," arr=($access_name) IFS="$OLD_IFS" echo "####################### mv log ${log_time} #####################################" >>${log_path} for s in ${arr[@]} do src_path=$nginx_path"/"$s"/"access_$s.log #echo $nginx_path"/"$s"/"access_$s.log echo "####($s)_ start_${log_time} ####" >> ${log_path} if [ -f "$src_path" ]; then mv $src_path $bak_path$s"/"access_${log_time}.log 2>> ${log_path} #防止文件过大或过多 每个进行复制和发送变量 kill -USR1 `cat ${nginx_pid_path}` #echo " $s move Success " >>${log_path} else echo "##($s)_NOT_FIND_FILE_${log_time} ##" >> ${log_path} fi echo "####($s)_end_${log_time} ######" >> ${log_path} echo " " >>${log_path} done echo "######################## END LOG #################################################" >> ${log_path} echo "" >>${log_path} echo "" >>${log_path}
以上就介绍了nginx 或tengine 访问日志分割处理,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。