Shell脚本切割日志

Posted imbadguy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shell脚本切割日志相关的知识,希望对你有一定的参考价值。

我们经常会遇到某个日志文件会特别大的情况,比如nginx记录的日志文件,怎么才能够在进程正常运行的情况下切割日志呢,看下面的代码片段

#!/bin/bash

_nginx_home="/usr/local/openresty/nginx"
_log_home="/tmp"
_time=$(date +%Y%m%d%H%M)
mv ${_nginx_home}/logs/ma.log ${_log_home}/ma-${_time}.log
kill -USR1 $(cat ${_nginx_home}/run/nginx.pid)

rm -rf ${_log_home}/ma-*.log

 

以上是关于Shell脚本切割日志的主要内容,如果未能解决你的问题,请参考以下文章

Shell脚本实现 tomcat 日志定时切割

shell脚本:日志切割与上传

linux shell:nginx日志切割脚本

tomcat 日志切割shell脚本

shell脚本切割tomcat日志文件

Linux shell脚本按日期 切割pm2日志