«

nginx日志切割脚本分享

时间:2024-3-2 15:33     作者:韩俊     分类: Linux



#!/bin/bash
Logs_path="/data/Application/nginx/logs"
Pid_path="/data/Application/nginx/nginx.pid"
Month=`date +%Y-%m`
Date=`date +%Y-%m-%d`
Time=`date +%H`
WaitTime=$((24*60*60))

LogCut()
{
cd $Logs_path
mkdir -p $Month
while true
do
mv $Logs_path/access.log $Logs_path/$Month/access_$Date.log
kill -USR1 `cat ${Pid_path}`
done
sleep $WaitTime
return 0
}

case $1 in
start)
LogCut >/dev/null &

stop)
kill -9 `ps aux | grep LogCut | grep -v grep | awk '{print $2}'`>/dev/null

restart)
kill -9 `ps aux | grep LogCut | grep -v grep | awk '{print $2}'`>/dev/null
LogCut >/dev/null &

*)
echo "Usage ERROR!Please use "start" or "stop" or "restart"!"
esac

标签: linux

热门推荐