【shell脚本】nginx每天自动切割日志脚本
2015-06-30 19:08
916 查看
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
相关文章推荐
- HDFS常见shell命令
- Shell学习--正则表达式
- shell脚本调试中打开set选项
- shell文件读取及字符串分隔符
- Exchange 2010 PowerShell
- SylixOS动态加载器系列文章(3) 使用API及shell命令
- linux的shell
- Shell 重定向 &>file,2>&1,1>&2 的区别
- shell基本语法
- shell基本语法
- shell学习三十三天----关于重定向
- Shell脚本学习
- linux shell字符串操作
- verify who reload the lab with shell
- generate hss profile via shell
- 出现 -bash: setup: command not found
- shell中的大括号和小括号
- shell中的大括号和小括号
- shell学习之路:流程控制(while)
- shell学习之路:流程控制(for)