博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

Ajian的学习天地


简单人生 Simple Life

生存是为了自己。。。。 而生活是为了所有的人。。。。自己快乐就能感染不快乐的人。自己学会快乐也就教会别人快乐。。。。 所以从现在起学会生活,学会快乐。。-----Ajian

  ajian.cublog.cn

关于作者
姓名: Ajian
年龄: 21
职位: 系统工程师
Q Q:  63894624
MSN:  5root@live.cn
mail: 5root@live.cn
   转眼一年过去了,凭着自己的热情和执着,实现了自己不少的愿望,可以慢慢还我欠下的所有的情,其中不枉有很多艰辛也有很多乐趣,新的一年继续加油!A ZA A ZA ^_^
   补充句我的Blog搬家了,新家的地址http://www.AjianZone.cn
|| << >> ||
我的分类


Shell程序集锦四——邮件发送系统信息
    前言:这个Shell程序是用来将系统收集的信息,通过邮件的方式发给多个人,在写这个程序的时候参考了其它人的程序,有两个程序一个是可以群发,但发出去的格式不对,一个发出去的格式正确了,但只能单独发送,所以我整合了两个程序。
——Ajian
 

#!/bin/sh
#Modify by Ajian
#Time : 071111

function echo_help(){
echo "Usage:"
echo "sh mailto.sh -to mailaddr -file messagefilename [-from frommailaddr]

[-subject mailsubject] [-fname showname] [-tname toshowname]"
}
LOG=/root/mailmes.log
for email in `cat mail.list`
do
echo "$email" >> $LOG
emailname="name"
messagebody="message"
from=Ajian@youdomain.com.cn
#fromname="MailReport"
fromname="fromname"
#subject="Mail Report"
subject="系统信息"

until [ $# -eq 0 ]
do
tmpV=$1

if [ $tmpV = "-from" ] ; then
shift
tmpV=$1
from=$tmpV
elif [ $tmpV = "-to" ] ; then
shift
tmpV=$1
email=$tmpV
elif [ $tmpV = "-subject" ] ; then
shift
tmpV=$1
subject=$tmpV
elif [ $tmpV = "-file" ] ; then
shift
tmpV=$1
messagebody=$tmpV
elif [ $tmpV = "-fname" ] ; then
shift
tmpV=$1
fromname=$tmpV
elif [ $tmpV = "-tname" ] ; then
shift
tmpV=$1
emailname=$tmpV
elif [ $tmpV = "--help" -o $tmpV = "-h" ] ; then
echo_help
exit 1
fi

shift
done
if ! test -f ${messagebody} ; then
echo "${messagebody} not exists!" >> $LOG
echo_help
exit 2
fi

echo "begin send..."  >> $LOG

echo -e "To: \"${emailname}\" <${email}>\nFrom: \"${fromname}\"

<${from}>\nSubject: ${subject}\n\n`cat ${messagebody}`" |

/usr/sbin/sendmail -t

echo "send OK." >> $LOG
done
rm -f /root/$messagebody
echo "$messagebody has deleted....." >> $LOG

 
另外附上我参考的程序。
       
#!/bin/sh
source /etc/profile
 
dirpath="/root"
from="service@yourmail.com"
msgdate="`date +"%a, %e %Y %T %z"`"
sub=$1   #...................
 
cd $dirpath
echo -e "START TIME...." > mails.log
date +"%Y-%m-%d [%T]" >> mails.log
for line in `cat mail.list`     #.mail.list............MAIL........
do
echo -e "Date: $msgdate" > msg.tmp   
echo -e "From: $from" >> msg.tmp
echo -e "To:$line" >> msg.tmp
echo -e "Subject: $sub" >> msg.tmp
echo -e "Mime-Version: 1.0" >> msg.tmp
echo -e "Content-Type: text/html; charset=gb2312" >> msg.tmp
echo "$line" >> mails.log
echo -e "\n" >>msg.tmp
cat message >>msg.tmp
dos2unix msg.tmp &> /dev/null
cat msg.tmp |sendmail -t
done
echo "END TIME" >> mails.log
date +"%Y-%m-%d [%T]" >> mails.log

发表于: 2007-12-16,修改于: 2007-12-16 15:04,已浏览300次,有评论0条 推荐 投诉


网友评论
 发表评论