shell 自动发送邮件脚本

环境:ubuntu 12.04
涉及命令: mutt,crontab 

1. 安装mutt: sudo apt-get install mutt (发送邮件命令,还有类似mail...个人觉得这个好用)
2. 把你要发送的邮件编辑成txt文件,这里比如:mail.txt(里面有你要发的内容,绝对路径:/home/alean/Txt/mail.txt)
3. 编辑好你的发送邮件脚本:(假设路径为:/home/alean/sh/email.sh)
   #!/bin/bash
   #name:email.sh
   #注:下面小括号里面的内容为注释,脚本中不需要
  
   mutt -s "Hell World(邮件主题)" 伴读小书僮@163.com(这里是收件地址) </home/alean/Txt/mail.txt

4. 编译好的你定时脚本:(假设路径:/home/alean/sh/crontab.cron)
   #!/bin/bash
   #name:crontab.cron
   #以下表示每天16:12分时,发送/home/alean/sh/email.sh这个脚本(具体时间设置可以参考crontab命令)

   12 16 * * * /bin/bash /home/alean/sh/email.sh
5. 运行:crontab /home/alean/sh/crontab.cron



你可能感兴趣的:(linux,定时发送邮件)