闲话不多说直接上脚本,再次感谢群里的大牛们,是你们让我少走了好多弯路!

#!/bin/sh
ip=`ifconfig|grep 192.168|awk '{print $2}'|sed 's/addr://g'`;    ###过滤IP地址
time=`date +%F-%H:%M`;
mail_address="xxx@126.com";
tmpfile=/tmp/check-disk.txt
a=`df -h | grep 'sda1'|awk '{print int($5)}'`;   ###指定过滤的硬盘分区
touch /tmp/check-disk.txt

echo "From :$ip" > $tmpfile     ###这里用“>”的意思是覆盖,保证每次发邮件的内容都是新的。
echo "DateTime:$time" >> $tmpfile
echo "Info :yourname" >> $tmpfile
echo "disk_status_use=$a%" >> $tmpfile

    if [[ "$a" > 85 ]]; then       ###指定分区的磁盘使用空间大于85%就报警
           /bin/mail -s "warning ! $HOSTNAME disk is full !" $mail_address < $tmpfile
    else
           /bin/mail -s "$HOSTNAME disk is ok !" $mail_address < $tmpfile
    fi