shell 官网http状态之发送邮件

先下载SendEmail : http://caspian.dotconf.net/menu/Software/SendEmail/
解包看readme安装SendEmail

#!/bin/bash
email_reciver=[email protected]
#发送者邮箱
email_sender=[email protected]
#邮箱用户名
email_username=[email protected]
#邮箱密码
#使用qq邮箱进行发送需要注意:首先需要开启:POP3/SMTP服务,其次发送邮件的密码需要使用在开启POP3/SMTP服务时候腾讯提供的第三方客户端登陆码。
email_password=******************
#email_psasword=******************

#smtp服务器地址
email_smtphost=smtp.qq.com

email_title="公司官网状态"
email_content=`curl -I -m 5 -s -w "%{http_code}\n" -o /dev/null  www.moonx.ai`
currTime=$(date +"%Y-%m-%d %T")
echo $currTime $email_content >> /home/xuehui/email/sendEmail-v1.56/email.log

cd /home/xuehui/email/sendEmail-v1.56
if [[ $email_content -ne '200' && $email_content -ne '000' ]];then
	echo `./sendEmail -f ${email_sender} -t ${email_reciver} -s ${email_smtphost} -u ${email_title} -xu ${email_username} -xp ${email_password} -m ${email_content} -o message-charset=utf-8 -o tls=no` >> /home/xuehui/email/sendEmail-v1.56/email.log
fi
#参考
#https://www.jianshu.com/p/6a7e764192bd
#https://www.cnblogs.com/fjping0606/p/6774348.html #版本不兼容,增加参数-o tls=no 选项
#https://blog.csdn.net/u011734144/article/details/54576469 #crontab定时任务不执行的原因,要写绝对路径

定时任务
crontab -e

0 */1 * * * bash /home/xuehui/email/sendEmail-v1.56/jiankong.sh

每小时会测试一下官网状态。

参考
shell 脚本发送邮件
版本不兼容,增加参数-o tls=no 选项
crontab定时任务不执行的原因

Ka.
发布了23 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/guaiderzhu1314/article/details/96129120
今日推荐