某个目录日志文件越来越大,定期将日志清理掉,以免撑爆服务器。
另外写日志时精简,去掉不必要的日志;
limit-log.sh:控制日志的行数,超过就删掉之前的。
[monitor]$ more ~/bin/limit-log.sh#/bin/shfunction limitlog(){ local logfile=$1 local maxline=$2 linecount=`/usr/bin/wc -l $logfile|awk '{PRint $1}'`; echo file:$logfile, line count=$linecount. line limit=$maxline. if [ ${linecount} -gt ${maxline} ];then delcount=`expr ${linecount} - ${maxline}`; echo delcount=$delcount sed -i "1,${delcount}d" $logfile echo $delcount lines deleted else echo do nothing. fi}#handle monitor.datdatelimitlog /home/monitor/log/monitor.dat 10000000#handle sar.loglimitlog /home/monitor/log/sar.log 20000000#handle redisinfo.logdatelimitlog /home/monitor/log/redisinfo.log 50000000dateecho #############################其中 sar.log redisinfo.log monitor.dat是要限制的日志文件, 后面的数字是行数。
新闻热点
疑难解答