【shell脚本】nginx每天自动切割日志脚本
nginx每天日志量比较大的时候,最好每天自动切割,存储,这样可以方面以后的查询和分析
#!/bin/sh
###################
#filename: nginx_log_rotate.sh
#vsersion: 0.1v
#1 0 * * * /bin/sh /home/project/monitor/nginx_log_rotate.sh >/dev/null 2>&1
###################
logs_path="/usr/local/openresty/nginx/logs"
old_logs_path=${logs_path}/old
nginx_pid=`cat /usr/local/openresty/nginx/logs/nginx.pid`
time_stamp=`date -d "yesterday" +"%Y-%m-%d"`
mkdir -p ${old_logs_path}
#grep some mode file
for file in `ls $logs_path | grep log$ | grep -v '^20'`
do
if [ ! -f ${old_logs_path}/${time_stamp}_$file ]
then
dst_file="${old_logs_path}/${time_stamp}_$file"
else
dst_file="${old_logs_path}/${time_stamp}_$file.$$"
fi
mv $logs_path/$file $dst_file
#gzip -f $dst_file # do something with access.log.0
done
kill -USR1 $nginx_pid
【shell脚本】nginx每天自动切割日志脚本的更多相关文章
- nginx自动切割日志脚本
#!/bin/bash savepath_log='/data/logs' nglogs='/data/logs' mkdir -p $savepath_log/$(date +%Y)/$(date ...
- nginx切割日志脚本
nginx切割日志脚本 #!/bin/bash #cut nginx log #2018年9月26日14:26:44 #by jiajiezhao ########################## ...
- nginx tomcat 自动部署python脚本【转】
#!/usr/bin/env python #--coding:utf8-- import sys,subprocess,os,datetime,paramiko,re local_path='/ho ...
- Linux下配置Nginx按天切割日志
Nginx由于轻巧和高效的设计风格,去掉了一些额外的功能,所以它不像apache那样有自动切割日志. 建立一个脚本文件,并保证这个文件有可执行的权限:1.建立一个文件/root/log.nginx.s ...
- linux服务器自动切割日志
需求 由于nginx的日志会不停地增大,所以需要我们自己去切割日志,方便管理,需要达到以下的效果: 按日期自动切割日志,最小单位是天. 当日志总量超过一定量时,自动直接清理日志,限定总量不能超过100 ...
- shell实例利用crontab自动清除日志
shell实例利用crontab自动清除日志 程序运行会产生很多的日志,对于无用的日志手动删除比价麻烦,写一个自动执行的命令是很有必要的. 删除文件shell命令 find 对应目录 -mtime + ...
- nginx按天切割日志
原文链接:http://www.cnblogs.com/benio/archive/2010/10/13/1849935.html 本文只节选部分内容 Nginx自己没有日志分割的功能,一旦时间过长 ...
- nginx 自动化定时切割日志
NG在默认情况下,是始终输出到一个日志文件中,日志文件在nginx.conf中 : access_log logs/www.access.log main; 一个文件中不是很方便查找,分析数据, ...
- shell切割日志脚本
#!/bin/bash set -e source /etc/bashrc cd `dirname $` linenum=`wc -l userinfolist.txt | awk '{print $ ...
随机推荐
- TRIM ,LTRIM ,RTRIM ,空格过滤
- typeAliases别名
<configuration> <typeAliases> <!-- 通过package, 可以直接指定package的名字, mybatis会自动扫描你指定包下面的ja ...
- Redis设置Key的过期时间 – EXPIRE命令
EXPIRE key seconds 为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除. 操作key对生存时间的影响 生存时间可以通过使用 DEL 命令来删除整个 ...
- Future学习
接着上一篇继续并发包的学习,本篇说明的是Callable和Future,它俩很有意思的,一个产生结果,一个拿到结果. Callable接口类似于Runnable,从名字就可以看出来了,但 ...
- easing--缓动函数--贝塞尔函数--圆盘转动抽奖应用
http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js http://www.robertpenner.com/easing/penn ...
- WPF ListBox 获取listBoxItem
1.已知item的DataContext,获取ListBoxItem 1)ItemContainerGenerator.ContainerFromItem var selectedItem = Doc ...
- Oracle中查询和删除相同记录的3种方法
--创建测试表 )); ,'); ,'); ,'); ,'); ,'); ,'); commit; select * from test; --查询相同记录 ); select id,name fro ...
- Python之禅及其翻译
凡是用过 Python的人,基本上都知道在交互式解释器中输入 import this 就会显示 Tim Peters 的 The Zen of Python,但它那偈语般的语句有点令人费解,所以我想分 ...
- 码农代理免费代理ip端口字段js加密破解
起因 之前挖过爬取免费代理ip的坑,一个比较帅的同事热心发我有免费代理ip的网站,遂研究了下:https://proxy.coderbusy.com/. 解密 因为之前爬过类似的网站有了些经验,大概知 ...
- 基于Java配置Spring加Hibernate和再加SpringData时的差别
先在类路径application.properties jdbc.driverClassName = org.postgresql.Driver jdbc.url = jdbc:postgresql: ...