CentOS 6.5 經過命令行安裝發送郵件

1.安裝sendmail:

yum install sendmail

2.安裝mailx:

yum install mailx -y

 

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
相關文章
相關標籤/搜索