1. Prepare a test email account: such as [email protected], as the sender.
Note: Make sure the pop3/smtp of the mailbox is turned on;
as follows:
And activate the authorization code, write down the authorization code of your email address.
2. Edit the configuration file /etc/mail.rc and add the following content:
#########################
set [email protected]
set smtp=smtp.163.com
set [email protected]
set smtp-auth-password=刚刚的授权码
set smtp-auth=login
########################
3. Test it:
echo "test content!!" | mail -s "test" [email protected]
You can see that the [email protected] mailbox has received the email sent by the just configured [email protected] as the sender.
4. Write an alarm script:
#!/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