vim /opt/fenge.sh
#!/bin/bash
# filename: fenge.sh
day=$(date -d "-1 day" " %Y%m%d") #显示前一天的时间
logs_path="/var/log/nginx" #定义一个新的日志存放目录
pid_path="/usr/local/nginx/logs/nginx.pid" #定义变量pid_path将nginx进程id
[ -d $logs_path ] || mkdir -p $logs_path #创建日志文件目录
#移动并重命名日志文件
mv /usr/local/nginx/logs/access.log ${logs_path}/huigenb.com-access.log-{$day}
#重建日志文件
kill -USR1 $(cat $pid_path)
#删除30天前的日志文件
find $logs_path -mtime 30 -exec rm -rf {} \;
#find $logs_path -mtime 30 |xargs rm -rf
---->wq
chmod x /opt/fenge.sh
/opt/fenge.sh
ls /var/log/nginx
ls /usr/local/nginx/logs/access.log