Tomcat 日誌清理小腳本


#查看磁盤的大小和輸出格式:tomcat

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  5.8G   13G  31% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
/dev/vdb         40G   12G   26G  32% /data


#截取/data目錄使用磁盤大小的百分比bash

$ max=`df -h |awk 'NR==4''{print $5 }'| cut -d% -f1`
$ echo $max
32



#建立清除日誌的腳本ide

cat clean_log.sh
#!/bin/bash
max=`df -h |awk 'NR==4''{print $5 }'| cut -d% -f1`
if [ "$max" -gt 75 ];then
    echo " " > /data/tomcat/logs/catalina.out
    find /data/tomcat/logs/ -type f -name "*.log" -mtime +5 | xargs rm -rf
    find /data/tomcat/logs/ -type f -name "localhost_*.txt" -mtime +7 |xargs rm -rf
fi



#建立計劃任務,每1小時運行腳本1次spa

$ crontab -l
0 * * * * /bin/sh /data/clean_log.sh
相關文章
相關標籤/搜索