shell指令碼實踐清除日誌

2021-09-20 21:02:26 字數 1372 閱讀 5595

在生產環境中日誌是運維人員了解和分析生產環境的第一手資料,但是日誌資訊的內容量相當龐大,特別在公有雲環境中執行的業務系統,一般系統盤在20g-40g左右,如果沒有合理的日誌管理方案,很容易出現儲存空間不夠的現象,總結了以下幾種日誌處理的簡單方式,作為自己的實踐筆記,同時和大家一起交流學習。

1、部分日誌行數太多,時間週期比較久,裡面沒有什麼很重要的價值資訊,我們可以刪除前面固定行數的日誌檔案;

1

find-name  filename -execsed-i'1,6000000d'{} \;

2、我們可以將部分日誌直接刪除,由於rm是乙個比較危險的命令,所以一般情況都不會去使用,所以有折中的辦法就是用mv替換剪下到某乙個目錄然後進入目錄執行刪除命令。

1

2

3

4

5

6

7

8

find./     -mtime +30  -execrm-f  {} \;

logpath=/usr/tomcats/apache-tomcat-7.0.68-rxd/logs/

logname1=localhost_access_log.*

cd$logpath ;echo$logpath  &&

find./     -mtime +30  -execmv{}/tmp/\;

#find   ./  -name  *.txt   -mtime +30  -exec mv {}  /tmp/ \;

cd/tmp/&&rm-f  *.log &&rm-f *.txt

exit0

shell指令碼定時清除日誌檔案

bin bash clearfile 獲取資料夾內,檔案大小 m為單位 和檔案路徑 呼叫clear函式清空檔案 clear filesizeandfile clear echo 檔案大小 filesize echo 檔案路徑 filepath echo 磁碟空間 disksize 獲取檔名 file...

使用shell指令碼清除日誌的策略

usr bin env bash file path 日誌路徑 file size du m awk 日誌路徑下的檔案大小 default size 35 1024 預設乙個ip日誌檔案的總量為35g over size 現有的檔案總量是35g的倍數 flag size over size 1 ov...

清除tomcat日誌檔案的shell指令碼

bin bash d date f exec mydata script logs d tomcat log 2 1 echo 開始執行清除tomcat日誌檔案 find titakid tomcat7 logs mtime 10 name out exec rm rf if eq 0 then e...