码迷,mamicode.com
首页 > 系统相关 > 详细

linux下清理日志的脚本

时间:2014-09-18 16:48:04      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:linux服务器   清理日志文件   

需求:由于/var分区单独划分,给的分区大小才5G,日志写满了,需要写个脚本定时清理日志文件


#!/bin/bash

##delete log script ,write by xl

LOG_DIR1=/var/log

LOG_DIR2=/var/spool/mail

LOG_DIR3=/var/spool/mqueue

ROOT_UID=0

##Must be use root to run this script

if [ "$UID" -ne "$ROOT_UID" ]

then

  echo "Must be root to run this script."

  exit 1

 fi

cd $LOG_DIR1 || {

   echo "Can not change to necessary dircectory." >&2

   exit 1

  }

#把空设备重定向到文件里面

cat /dev/null > maillog && echo "Logs cleaned up."

cat /dev/null > maillog.1 && echo "Logs cleaned up."

cat /dev/null > maillog.2 && echo "Logs cleaned up."

cd $LOG_DIR2 || {

   echo "Can not change to necessary dircectory." >&2

   exit 1

  }

cat /dev/null > root && echo "Logs cleaned up."

cat /dev/null > stock && echo "Logs cleaned up."

###清除mqueue下的小文件

cd $LOG_DIR3

ls |xargs rm -rf


本文出自 “梦女孩” 博客,请务必保留此出处http://dreamgirl1314.blog.51cto.com/1159474/1554726

linux下清理日志的脚本

标签:linux服务器   清理日志文件   

原文地址:http://dreamgirl1314.blog.51cto.com/1159474/1554726

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!