Linux磁盤使用率監控

 以下是磁盤使用空間監控的腳本:但有兩個前提:1.開啓sendmail服務。2.vim /etc/mail.rc,新增一行:set smtp=smtp.server.com

        
     使用crontab設定好每幾分鐘運行一次。當某partition使用率超過90%時,即可發郵件報警。

 

#!/bin/bash
partitions=$(df -h|awk '{print $5}'|grep -v 'Use%')
[email protected],[email protected]

i=0
for partition in $partitions
do
 i=$((i+1))
 percent=$(echo $partition|tr -d '%')
 if [ $percent -ge '90' ];then
 showmenu=$(df -h|sed -n "1p")
 showpartition=$(df -h|grep -v 'Use%'|sed -n "${i}p")
 partitionname=$(df -h|grep -v 'Use%'|awk '{print $6}'|sed -n "${i}p")
 echo -e "Attention! $HOSTNAME's $partitionname Disk Occupancy rate has exceeded 90%,please notes !!\n\n$showmenu\n$showpartition\n\n"|mail -s "$HOSTNAME Partition Usage Alert!!" $recipients
 fi
done
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章