今天要做一个定时发邮件附件的功能,查了一下资料利用mutt实现起来简单参数介绍-a:邮件中添加附件-s:邮件的主题-n:不读取配置文件只用到-s 与 -a 执行一下命令:yum install -y
今天要做一个定时发邮件附件的功能,查了一下资料利用mutt实现起来简单参数介绍
-a:邮件中添加附件-s:邮件的主题-n:不读取配置文件
只用到-s 与 -a 执行一下命令:yum install -y mutt编写脚本,将文件压缩之后发送
#!/bin/bashbilldir=/usr/share/tomcat/XXXX/todaytime=`date -d yesterday +%Y%m%d` # 昨天if [ -d ${billdir} ]; then cd ${billdir} file_count=`ls -al | grep ${todaytime} | wc -l` if [ 2 -eq ${file_count} ];then tar -rvf /root/${todaytime}.tar *${todaytime}* # 将昨天生成的文件打包 fifiif [ -f /root/${todaytime}.tar ];then mutt [email protected] [email protected] -s "${todaytime}信息" -a /root/${todaytime}.tar </usr/local/mail/content_mail.txt fi
content_mail.txt 文件是要发送的文件内容,-s 表示发送的title,-a 是发送的附件,接下来定时任务,可以百度搜索crontab 即可
执行命令
-e:编辑-l:显示用户下的定时任务-i:删除定时任务crontab -e
每天六点发送昨天生成的文件
* 6 * * * * /usr/local/mail/sendmail.sh > /dev/null 2>&1
上面* 6 * * * *代表每天的六点执行 shell脚本
* 6 * * * *
分别代表:分(0-59),时(0-23),天(1-31),月(1-12),星期(0-7,0或7表示周日)碰到的问题1、在编辑定时任务时,由于多敲了一个*出现下面的错误"/tmp/crontab.XXXXcz4Lql":1: not commanderrors in crontab file, can't install.这时候就要检查写的对不对了