转自:https://blog.csdn.net/u011267225/article/details/82415380
#!/bin/sh
echo "开始执行检查MQTT状态的脚本..."
#这下面的路径,根据自己的实际安装目录来修改
cmd="cd emqx/"
$cmd
echo "已经进入/usr/local/emqx/目录下!开始执行检查MQTT状态指令..."
while true
do
check_result=`./bin/emqx_ctl cluster status`
echo "检查MQTT状态结果:$check_result"
#判断MQ状态
if [[ $check_result =~ "ip" ]] && [[ $check_result =~ "ip" ]]
then
echo "MQTT正常运行中..."
else
echo "MQTT已经瓜了,即将重启MQTT..."
# #这里杀进程是因为有些版本的MQ被内核Kill掉进程后,会有遗留的进程在
# kill_mqtt=`ps -ef | grep mqtt | grep -v grep | awk '{print $2}' | xargs kill -9`
# echo "杀死所有MQTT进程:$kill_mqtt"
# #启动MQ
# start_mqtt=`./emqttd start`
# echo $start_mqtt
curl 'https://oapi.dingtalk.com/robot/send?access_token=5163177c8f8' \
-H 'Content-Type: application/json' \
-d '
{"msgtype": "text",
"text": {
"content": "MQTT通知:监测到其中有mqtt服务器宕机,请登录检查"
}
}'
echo "发送http请求返回值--"
fi
sleep 30
done