shell 清空指定大小的日志文件

#!/bin/bash 
# 当/var/log/syslog大于68B时 
if ! [ -f /var/log/syslog ] 
then 
echo "file not exist!" 
exit 1 
fi 
if [ `ls -l /var/log/syslog|awk '{print $5}'` -gt $(68) ] 
then 
cat /var/log/syslog >> ~/log/history # 将日志备份 
echo >> ~/log/history # 增加一个空行 
date >> ~/log/history # 记录时间 
echo "-------------------------------------" >> ~/log/history 
echo > /var/log/syslog # 清空 
fi

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/9955753.html