#!/bin/bash

RESULT=$(df |grep "/dev/" |awk '{print $5}'|sort -nr |head -1|tr -d "%")
if [ "$RESULT" -gt "95" ];
then
     echo "disk usage of server `hostname` is nearly full !!" |mail -s "Server Warning" [email]root@abc.com[/email]
fi

exit 0

把这个脚本放在crontab里周期性执行就可以了。
如果运行脚本的服务器上没有mail smtp服务,那么要在mailrc中设置好mailrc否则发邮件发不出去。

set smtp=smtp.163.com
set smtp-auth=login
set smtp-auth-user=username
set smtp-auth-password=password