yum install msmtp -y

1 step

yum install msmtp -y

2 step

# cat ~/.msmtprc
# Set default values for all following accounts.
defaults
auth on
tls on
tls_starttls on
#tls_trust_file /etc/ssl/certs/ca-certificates.crt
tls_trust_file /etc/ssl/certs/ca-bundle.crt

# The account you will use
#account qqmail
account default
host smtp.exmail.qq.com
port 587
from f@f.com
user f@f.com
password 123456
logfile ~/.msmtp.log

3 step 

[root@vm172-31-0-25 ~]# cat /usr/local/src/monitor_mongod.sh
#!/bin/bash

# 获取系统 IP 地址
ip_address=$(hostname -I | awk '{print $1}')

# 目标邮件地址(多个地址用逗号分隔)
email="a@a.com,b@b.com"
# 发送邮件的标题
subject="Mongod Process Alert on ip_address" # 发送邮件的内容 message="Mongod process is not running onip_address"

# 创建一个临时文件用于存放邮件内容
temp_mail=$(mktemp)

# 检查 mongod 进程是否存在
if ! pgrep -x "mongos" > /dev/null
#if ! pgrep -x "aaaa" > /dev/null
then
# 如果进程不存在,准备邮件内容
{
echo "From: monitor@a.com"
echo "To: email"echo"Subject:subject"
echo ""
echo "message"     } > "temp_mail"

# 发送邮件
while IFS=',' read -ra ADDR; do
for i in "ADDR[@]";domsmtp"i" < "tempmail"donedone<<<"email"
fi

# 删除临时文件
rm -f "$temp_mail"

4 step

# crontab -l
*/10 * * * * /usr/local/src/monitor_mongod.sh 1>/dev/null 2>/dev/null

 

posted @   GaoYanbing  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2023-06-05 centos7部署minio
点击右上角即可分享
微信分享提示