Requirement: Because/var partition separately, the size of the partition is 5G, the log is full, you need to write a script to clean up the log files regularly
#!/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 is use as root to run this script
If ["$UID"-ne "$ROOT _uid"]
Then
echo "must is 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
This article is from the "Dream Girl" blog, please be sure to keep this source http://dreamgirl1314.blog.51cto.com/1159474/1554726
Script to clean up logs under Linux