日志切分

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

#!/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

定时运行:this

$ crontab -e

这将使用vi命令去修改crontab文件,增长日志

0 0 * * * sh /path/execute.sh
相关文章
相关标签/搜索