標籤: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下清理日誌的指令碼