sendEmail的主页http://caspian.dotconf.net/menu/Software/SendEmail/
下载地址http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
#tar –zxvf sendEmail-v1.56.tar.gz
#cd sendEmail-v1.56
#cp sendEmail /usr/local/bin
然后给确认确实它具有执行权限
ll /usr/local/bin/sendEmail
-rwxr-xr-x 1 root root 77882 11-03 14:23 /usr/local/bin/sendEmail
写脚本内容如下:
#!/bin/sh
# configurations
# computer 设备名称
# target 监控目标
# watcher 跟踪者(邮箱)
computer="java"
target="/home/java/apache-tomcat-7.0.81-src"
date_time=$(date +%c)
# 收件人
email_addressee="dawddawdsadwa@163.com"
# 发件人
email_sender="aadwda@163.com"
# 发件人用户名
email_user="aadwda@163.com"
# 发件人密码
email_password="admin"
# smtp服务器地址
email_smtp="smtp.163.com"
# 邮件标题
email_title=${computer}"TOMCATerror-"${date_time}
# 邮件内容
email_content=${computer}"---"${target}"\n在"${date_time}",Tomcat进程意外关闭\\nshell脚本搜索不到Tomcat进程PID,请及时处理。"
#tomcat=$(ps -ef|grep $$target | grep -v grep | awk '{print $2}')
tomcat=`ps -ef|grep $target | grep -v 'grep\|tail' | awk '{print $2}'`
if test -z ${tomcat}
then
echo $(date +%F" "%T)"--info--:success"
/usr/local/bin/sendEmail -f ${email_sender} -t ${email_addressee} -s ${email_smtp} -u ${email_title} -xu ${email_user} -xp ${email_password} -m ${email_content} -o message-charset=utf-8
echo $(date +%F" "%T)"--info--:success"
else
echo $(date +%F" "%T)"--info--:tomcat£¬pid="${tomcat}
echo $(date +%F" "%T)"--info--:error"
/usr/local/bin/sendEmail -f ${email_sender} -t ${email_addressee} -s ${email_smtp} -u ${email_title} -xu ${email_user} -xp ${email_password} -m ${email_content} -o tls=no
echo $(date +%F" "%T)"--info--:error"
fi
如果出现以下错误:
就是密码填写错误 密码是指邮箱授权密码,而不是邮箱登入密码