1. 程式人生 > >shell 清空指定大小的日誌檔案

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