[root@LOG01 ~]# cat   /data/sh/check_disk.sh
#!/bin/bash
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# check_disk.sh 
# ¼ì²éIDC»ú·¿ËùÓдÅÅ̿ռ䣬³¬¹ý60%·¢³öÓʼþ£¬³¬¹ý70%·¢¶ÌÐÅ
# 2012-10-25
# Li.Yingjie
# ËùÐèÎļþ£ºip.list phonenumber
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#

PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export PATH

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#mail
FROM="notify@yougou.com"
TO="fbzc@yougou.com"
#TO="huang.dz@yougou.com"
#TO=li.yj2@yougou.com
SMTP="smtp.exmail.qq.com"
USERNAME="notify@yougou.com"
PASS="poiuy123"
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#sms
sendsms=/usr/local/nagios/libexec/sms_send
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
Date=$(date +%Y%m%d)
Time=$(date +%Y%m%d_%H%M)
check="df -h |sed "s/%//g""
logmail=/data/sh/logs/check_disk_log/check_disk_$Time.mail.log
logsms=/data/sh/logs/check_disk_log/check_disk_$Time.sms.log
tmp=/data/sh/logs/check_disk_log/check_disk_$Time.tmp.log
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#

touch $logmail
touch $logsms

for ip in `cat /data/sh/ip.list`
do echo ========$ip======== > $tmp
    ssh -p 60777 $ip "$check" > $tmp
    if [ "$ip" = "10.10.10.137" ]||[ "$ip" = "10.10.10.196" ]||[ "$ip" = "10.10.10.199" ]||[ "$ip" = "10.10.10.181" ]||[ "$ip" = "10.10.10.214" ]||[ "$ip" = "10.10.10.141" ]||[ "$ip" = "10.10.10.140" ]||[ "$ip" = "10.10.10.137" ];then
        Evalue=85
        sed -i '/backups_bak0512/d' $tmp
    elif [ "$ip" = "10.10.10.90" ];then
        Evalue=80
    else
        Evalue=70
    fi 
    a=`awk "\\$5>=$Evalue" $tmp | grep -Ev "Îļþϵͳ|Filesystem"`
    b=`awk '$5>=85' $tmp | grep -Ev "Îļþϵͳ|Filesystem"`
    if [ ! -n "$a" ]; then
        echo "$ip is ok"
     else
        echo ========$ip======== >> $logmail
        awk "\$5>=$Evalue" $tmp | grep -Ev "Îļþϵͳ|Filesystem" >> $logmail
           if [ ! -n "$b" ]; then
               echo "$ip is ok"
            else
               echo =$ip= >> $logsms
               awk '$5>=80' $tmp | grep -Ev "Îļþϵͳ|Filesystem" >> $logsms
           fi
    fi
done

d=`cat $logmail`
if [ ! -n "$d" ]; then
   echo "all disk is ok"
 else
   /usr/local/bin/sendEmail -f notify@yougou.com -t $TO -s $SMTP -xu $USERNAME -xp $PASS -u "IDC Disk space check " -o message-file="$logmail"
fi


#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
 c=`cat $logsms`
    if [ ! -n "$c" ]; then
        echo "all disk is ok"
     else
        for phone in `cat /data/sh/phonenumber`
        do $sendsms "$c" "$phone"
        done
    fi
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#

rm -fr $tmp
文档更新时间: 2019-07-09 10:58   作者:月影鹏鹏