http://caspian.dotconf.net/menu/Software/SendEmail/ 邮件的地点
每天需要多次备份文件,所做操作比较机械化,所以就想在shell下自动帮我备份文件,开始想使用mail命令但是mail命令发邮件需要开启sendmail服务,我只是一台客户端,开个sendmail没有必要,于是乎,在网上找了好久,才发现mutt是个好东西。
在ubuntu下安装mutt很方便,只需要sudo apt-get install mutt,另外需要安装msmtp,一个发邮件的小工具,sudo apt-get insall msmtp。这两个文件都很小,一下子就装完了。
接下来是配置文件,也很简单,这里我引用网上别人的配置和命令行。另外在文件的最后,附上一个脚本文件,是通过发送电子邮件自动备份。
=====================================引用================================
MUTT
系统全局设置/etc/Muttrc,如果使用某个系统用户,可以在~/.muttrc中设置。
vi /etc/Muttrc
set sendmail="/usr/bin/msmtp"
set use_from=yes
set realname="FengYuBin"
set from=fyb@163.com
set envelope_from=yes
MSMTP
创建~/.msmtprc和~/.msmtp.log,分别为配置和日志文件。
vi .msmtprc
account default
host smtp.163.com
from fyb@163.com
auth plain
user fyb
password 123456
logfile ~/.msmtp.log
由于password是明码,所以我们需要修改此文件的权限。
chmod 600 .msmtprc
touch ~/.msmtp.log
查看SMTP服务器是否支持认证的TLS加密:
[oracle@oracle ~]$ msmtp --host=smtp.163.com --serverinfo
SMTP server at smtp.163.com (m5-86.163.com [202.108.5.86]), port 25:
163.com Anti-spam GT for Coremail System (163com[20050206])
Capabilities:
PIPELINING:
Support for command grouping for faster transmission
AUTH:
Supported authentication methods:
PLAIN LOGIN
到这里,你可以使用mutt来发送邮件了,我们测试一下。
echo "test" |mutt -s "my_first_test" fyb@gmail.com
-s "subject"
-c "carbon-copy"
echo "test" |mutt -a dbms_stats.txt -s my_first_test fyb@gmail.com
echo -e "文字描述,可以带参数$allname" | mutt -a "附件(写好路径)" -a "附件2(写好路径)" aa@163.com,bb@yahoo.com.cn(收信人) -c cc@163.com,dd@163.com (抄送)
观察.msmtp.log文件,如果有错会在日志文件中被报告出来,当然,成功发送的日志也会出现在此日志文件内。
到这里发送邮件的过程已经全部完成,接下来要做的事就简单了,我们假设每天凌晨定时发送信件给公司某用户,可以编写脚本处理。
mail.sh
#!/bin/sh
content="you can tell your colleague what something to do at tomorrow"
echo "$content" |mutt -s "hi Jacky" Jacky's_email
OK,上面这些就是我实现自动发送邮件的全部过程,怎么样,很轻松吧!
=================================下面是我脚本文件=======================
#!/bin/bash
cd
fileName=bak\($(date +%Y%m%d%H%M)\).zip #产生文件名
zip $fileName -r fw2 #将需要备份的目录fw2打包
sleep 1 #睡眠一秒,让zip打包完成的文件写入硬盘
echo "Sending mail..."
#调用mutt发送文件
echo "firewall code src backup" | mutt -s "$fileName" springtty@163.com -a "$fileName"
echo "Sent OK"
After motion is installed, we have to configure Motion to save captured images in a remote server, to do that we need to install wput a command line FTP client that upload the captured photos by motion , to an remote FTP server. You can install wput by entering the following command into a terminal :
sudo apt-get install wput
- Now you can configure Motion to use wput to upload captured photos by adding the lines bellow to motion.conf file :
gedit /etc/motion/motion.conf
And add these lines at the end of the file:
# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)# The filename of the picture is appended as an argument for the command.on_picture_save wputftp://USERNAME:PASSWORD@REMOTE SERVER %f
Now save and close.
After motion is installed, we have to configure Motion to save captured images in a remote server, to do that we need to install wput a command line FTP client that upload the captured photos by motion , to an remote FTP server. You can install wput by entering the following command into a terminal :
sudo apt-get install wput
- Now you can configure Motion to use wput to upload captured photos by adding the lines bellow to motion.conf file :
gedit /etc/motion/motion.conf
And add these lines at the end of the file:
# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)# The filename of the picture is appended as an argument for the command.on_picture_save wputftp://USERNAME:PASSWORD@REMOTE SERVER %f
Now save and close.
You should now be able to open a web interface for Motion now by typing in localhost:8000 from the server itself or XXX.XXX.X.XXX:8000 from another computers web browser. To view a live stream of your webcam type localhost:8001 from the server itself or XXX.XXX.X.XXX:8001 from another computers web browser. You can change settings from this interface here too, you can even make Motion generate it’s own config files to fit your setup exactly.