nginx自动清理脚本

linux

#!/bin/bash
logs_path="/usr/local/nginx/logs"
bak_path="/usr/local/nginx/logs/bak"
DAYS=15
mv ${logs_path}/access.log ${bak_path}/access_$(date -d "yesterday" +"%Y%m%d%H%M%S").log
mv ${logs_path}/error.log ${bak_path}/error_$(date -d "yesterday" +"%Y%m%d%H%M%S").log
#mv ${logs_path}access.log ${logs_path}access_$(date +"%Y年%m月%d日%H时%M分%S秒星期%w").log
#mv ${logs_path}access.log ${logs_path}access_$(date -d "yesterday" +"%Y年%m月%d日%H时%M分%S秒星期%w").log
nginx -s reload
find ${bak_path} -name "*.log" -type f -mtime +$DAYS -exec rm {} \;

windows 

windows
@echo off
D:
set NGINX_PATH="D:\javaServer\nginx 1.13.10.1 Crow"
cd %NGINX_PATH%
rem date格式:Wed 11/02/2016
set today=%date:~0,4%-%date:~5,2%-%date:~8,2%
set dir="D:\javaServer\nginx 1.13.10.1 Crow\logs\backup"

rem access log
move %NGINX_PATH%\logs\access.log %dir%\access-%today%.log
move %NGINX_PATH%\logs\error.log %dir%\error-%today%.log


nginx_basic.exe -s reload

rem 删除 D:\javaServer\nginx\logs目录及子目录下,修改时间大于15天的、tmp结尾的文件
forfiles /p "D:\javaServer\nginx 1.13.10.1 Crow\logs\backup" /s /m *.log /d -15 /c "cmd /c del /f /q /a @path"

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值