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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值