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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。