1.安装sendmail:
2.安装mailx:
3.编辑发送的配置文件:
vi /etc/mail.rc
#在最后添加以下配置:
set from="991769422@qq.com" smtp="smtp.qq.com"
set smtp-auth-user="991769422@qq.com" smtp-auth-password="******"
set smtp-auth=login
4.测试邮件发送:
#1) 无邮件正文
mail -s "主题" 收件地址
mail -s "测试" 991769422@qq.com
#2) 有邮件正文
mail -s "主题" 收件地址< 文件(邮件正文.txt)
mail -s "邮件主题" 991769422@qq.com < /data/test.txt
echo "邮件正文" | mail -s 邮件主题 收件地址
echo "邮件正文内容" | mail -s "邮件主题" 991769422@qq.com
cat test.txt | mail -s 邮件主题 收件地址
cat /data/test.txt | mail -s "邮件主题" 991769422@qq.com
#3) 带附件
mail -s "主题" 收件地址 -a 附件 < 文件(邮件正文.txt)
mail -s "邮件主题" 991769422@qq.comm -a /data/test.tar.gz < /data/test.txt
6.脚本文件:
#*************************************************************************
# FileName : disk_capatiy_alarm.sh
#*************************************************************************
# Author : joshua317
# CreateDate : 2017-09-11
# Description : this script is mointoring the linux disk
# capacity, if disk used more than 80%,
# then it will send a alarm email
#*************************************************************************
#!/bin/bash
host=`hostname`
for d in `df -P| awk '{print $5}' | sed 's/%//g'`
do
if [[ "$d" =~ ^[0-9]*$ ]]&&[ $d -gt 80 ];then
#echo $d
echo $host"'s disk will unAvail, please process as quickly as possible" | mail -s "the disk will run out" 991769422@qq.com
exit;
fi
done
7.定时脚本
#磁盘空间检查,每1小时执行一次
crontab -e
* */1 * * * /bin/sh /usr/local/shell/disk_capatiy_alarm.sh