首页 > √linux > linux使用Msmtp mutt shell自动发邮件(备份mysql)
viyin.net

linux使用Msmtp mutt shell自动发邮件(备份mysql)

2009年8月21日 发表评论 阅读评论

linux使用Msmtp shell发邮件(备份mysql)
因为数据库有插件自动备份到邮箱,本例示范web数据备份。
需要用到mutt 和 这两款软件
1.编译安装软件

  1. tar jxvf msmtp-1.4.16.tar.bz2
  2. ./configure --prefix=/usr/local/msmtp &&make &&make install
  3. tar -xzvf mutt-1.5.11.tar.gz
  4. ./configure --prefix=/usr/local/mutt &&make &&make install

2.查看msmtp配置文件路径

  1. [root@vi bin]# ./msmtp --ver
  2. msmtp version 1.4.16
  3. TLS/SSL library: OpenSSL
  4. Authentication library: GNU SASL
  5. Supported authentication methods:
  6. plain cram-md5 digest-md5 gssapi external login
  7. IDN support: enabled
  8. NLS: enabled, LOCALEDIR is /usr/local/msmtp/share/locale
  9. System configuration file name: /usr/local/msmtp/etc/msmtprc
  10. User configuration file name: /root/.msmtprc
  11.  
  12. Copyright (C) 2008 Martin Lambers and others.
  13. This is free software. You may redistribute copies of it under the terms of
  14. the GNU General Public License .
  15. There is NO WARRANTY, to the extent permitted by law.


3.配置msmtp的配置文件

  1. [root@vi ~]# vi .msmtprc
  2. defaults
  3. #-------该文件要存在,不然没有日志,需要手工建立
  4. logfile /usr/local/msmtp/msmtp.log
  5. account vi
  6. host smtp.yahoo.cn
  7. from viyin@yahoo.cn
  8. auth plain
  9. user viyin@yahoo.cn
  10. password viyin.net
  11. account default : viyin
  12. [root@vi ~]#

测试一下

  1. /usr/local/msmtp/bin/msmtp viyin@yahoo.cn
  2. test,viyin
  3.  
  4. crtl +d 退出

tail -f /usr/local/msmtp/msmtp.log 查看日志
然后再进入到上面的邮件中,看看信收到没有
4.配置mutt

  1. [root@vi viyin]# cat ~/.muttrc
  2. set sendmail="/usr/local/msmtp/bin/msmtp"
  3. set use_from=yes
  4. set realname="vi"
  5. set from=viyin@yahoo.cn
  6. set envelope_from=yes

5.测试发信

  1. [root@vi viyin]# echo "viyin.net test" | mutt -s "messages" 7676002@qq.com

6.备份脚本

  1. #!/bin/bash
  2. cd /www/web/
  3. tar -zvcf backup/web_viyinnet_`date +"%y-%m-%d-%H"`.tar.gz viyinnet
  4. echo "web backup" | mutt -s "web_viyinnet_`date +"%y-%m-%d"`" -a /www/web/backup
  5. /web_viyinnet_`date +"%y-%m-%d-%H"`.tar.gz vi@viyin.net

7. 加入crontab自动执行

  1. 30 6  * * * /root/webbackup.sh

错误提示:
msmtp: /root/.msmtprc: must have no more than user read/write permissions
解决办法:更改权限 chmod 600 .msmtprc
一定只能是600权限

viyin.net
分类: √linux 标签: , , , , ,