Linux中发送告警邮件

1.准备一个测试邮箱账号:如[email protected],作为发件人。

注意:保证邮箱的pop3/smtp是开启状态;

如下:

并且开通授权码,记下自己邮箱的授权码。

2.编辑配置文件/etc/mail.rc,添加如下内容:

#########################
set [email protected]
set smtp=smtp.163.com
set [email protected]
set smtp-auth-password=刚刚的授权码
set smtp-auth=login
########################

3.测试一下:

echo "test  content!!" | mail -s "test"  [email protected]

            可以看到[email protected]邮箱已经收到了刚刚配置的[email protected]作为发件人发过来的邮件。

4.写一个告警的脚本:

#!/bin/bash

rate=$(df -h | grep "/dev/sda2" | awk '{printf $5}' | cut -d "%" -f 1)

if [ $rate -ge 20 ];then
        echo "warning!/dev/sda2 is full!!"
        echo "/dev/sda2 is full!!please handle now!!" | mail -s "/dev/sda2 is full" [email protected]

fi

猜你喜欢

转载自blog.csdn.net/liuwkk/article/details/108809695