【shell脚本】nginx每天自动切割日志脚本
2015-06-30 19:08
801 查看
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
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- Awstats处理多apache日志
- 网站502与504错误分析
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 典型入侵日志分析
- 把Lua编译进nginx步骤方法
- MS SQL Server数据库清理错误日志的方法
- MSSQL 2005/2008 日志压缩清理方法小结
- SQL Server误区30日谈 第19天 Truncate表的操作不会被记录到日志
- mysql binlog二进制日志详解
- web 应用中常用的各种 cache详解
- window+nginx+php环境配置 附配置搭配说明
- javascript实现的图片切割多块效果实例
- C#实现线程安全的简易日志记录方法
- ORACLE DATAGUARD中手工处理日志v$archive_GAP的方法
- 某个aspx页面突然死了连日志也没有的解决方法