日志切分

随着项目运行,日志文件也变得越来越大,不方便定位问题。于是写了将日志文件切分的脚本,让服务器定时运行。

#!/bin/sh

# split the nohup file into pieces
# rules: 1. size: 20M per file 
#        2. split at 00:00 am 
#        3. named log_${currentday-1}_00xx
# Lawrence

this_path=$(cd `dirname $0`; pwd)

cd $this_path
current_date=`date -d "-1 day" "+%Y%m%d"`
split -b 20971000 -d -a 4 ./nohup.out ./nohupDir/log_${current_date}_

cat /dev/null > nohup.out

定时运行:

$ crontab -e

这将使用vi命令去修改crontab文件,增加

0 0 * * * sh /path/execute.sh
原文地址:https://www.cnblogs.com/horo/p/7902557.html