Ubuntu用命令行发邮件mutt,报警发短信通知
在ubuntu下用sendmail有點問題,主題發出去老為空。
干脆安裝mutt和msmtp,通過163的郵件系統發郵件。
sudo?apt-get?install?mutt,另外需要安裝msmtp,一個發郵件的小工具,sudo?apt-get?install?msmtp
配置mutt
?1、在?/etc/Muttrc?文件里最后加入5行
set?sendmail="/usr/bin/msmtp"
set?use_from=yes
set?realname="mozatmonitor"?????---》發件人顯示昵稱
set?from=mozatmonitor@163.com?????--》發件人地址
set?envelope_from=yes
-----------------如有編碼問題可以嘗試在后面加入----
set?charset="utf-8"
#set?send_charset="gb2312"
set?send_charset="utf-8"
set?locale?=?"zh_CN.UTF-8"
set?content_type?=?"text/html\;charset=utf-8"
?
2、編輯~/.msmtprc,如果這個文件不存在就創建一個,要錄屬于當前用戶和群組,該文件需要600權限,如果不是600權限會無法使用。
account?default
host?smtp.163.com???????????????---->郵件服務器地址
from?mozatmonitor@163.com????
auth?login???????????????????????????------>?認證方式用最傻的login
user?mozatmonitor
password?kkkkkk????????????????????----->kkkkkk替換成密碼
logfile?~/.msmtp.log
?
?
發送:
mutt?-s?"主題"?foo@sina.com.cn?-a?附件.txt?<郵件內容.txt
多聯系人多附件:
MailList=`cat?list.txt`
/usr/bin/mutt??-s?"主題"?$MailList?-a?附件1?-a?附件2??<?hello.txt
?
?##報警發郵件
1、扔腳本在后臺導入數據(這個腳本包含計算腳本運行時間):nohup?./import.sh?&
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | mozat@DellR410-DB4:~$?cat?import.sh??? #!/bin/bash ???? BEGINTIME=`date?+"%Y-%m-%d?%H:%M:%S"` ???? /usr/local/mysql-5.5.15/bin/mysql??-h?127.0.0.1?-P?3335??-uxxx?-pxxxxxx?<?/home/mozat/xxx.sql ???? ENDTIME=`date?+"%Y-%m-%d?%H:%M:%S"` begin_data=`date?-d??"$BEGINTIME"?+%s`????#把當前時間轉化為Linux時間 end_data=`date?-d??"$ENDTIME"?+%s` spendtime=`expr?$end_data?-?$begin_data`??#計算2個時間的差 ???? ???? echo?"it?takes?$spendtime?sec?for?dump?the?data?directory" echo?"it?takes?$spendtime?sec?for?dump?the?data?directory"?>/tmp/dump184_3335mofs2.txt |
?2、在crontab中每分鐘跑監控腳本,如果發現跑完,就發郵件給139郵件,這樣手機就會收到短信。
?
| 1 2 3 4 5 6 7 8 9 10 11 | mozat@DellR410-DB4:~$?crontab?-l */1?*?*?*?*?/bin/sh??/home/mozat/operation/xx/sendmail.sh mozat@DellR410-DB4:~$?cat??/home/mozat/operation/xx/sendmail.sh #!/bin/bash ??? counter=`ps?-ef?|?grep?import.sh?|?grep?-v?grep?|wc?-l` if?[?$counter?-eq?0?];?then ????????/usr/bin/mutt?-s?"back?is?finished"?13xxxxx@139.com?</home/mozat/operation/xx/hello.txt else ????????echo?"the??backup?is?running?now." fi |
轉載于:https://www.cnblogs.com/vk83/archive/2013/06/01/3112454.html
總結
以上是生活随笔為你收集整理的Ubuntu用命令行发邮件mutt,报警发短信通知的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创业需要些什么
- 下一篇: Android Launch Mode的