监控硬盘使用率并发送邮件报警

#!/bin/bash
DATE=$(date +%F" "$H:$M)
IP=$(ifconfig | awk -F'[ :]+' NR==2'{print $4}')
MAIL="13102133719@163.com"
TOTAL=$(fdisk -l |awk -F'[: ]+' 'BEGIN{OFS="="}/^Disk \/dev/{printf "%s=%sG,",$2,$3}')
PART_USE=$(df -h |awk 'BEGIN{OFS="="}/^\/dev/{print $1,int($5),$6}')
for i in $PART_USE; do
    PART=$(echo $i |cut -d"=" -f1)
    USE=$(echo $i |cut -d"=" -f2)
    MOUNT=$(echo $i |cut -d"=" -f3)
    if [ $USE -gt 80 ]; then
        echo "
        Date: $DATE
        Host: $IP
        Total: $TOTAL
        Problem: $PART=$USE($MOUNT)
        " | mail -s "Disk Monitor" $MAIL
    fi
done

 

posted @ 2019-03-16 12:33  New_Journey  阅读(308)  评论(0编辑  收藏  举报