wei/sh/check_xtpsvr.txt
2026-06-26 10:10:40 +08:00

29 lines
769 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 配置企业微信机器人Webhook URL
WEBHOOK_URL="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=your_webhook_key"
# 检查xtpsvr进程是否运行
if ps -ef | grep -q '[x]tpsvr'; then
exit 0 # 进程正常运行,静默退出
else
# 构造告警消息
ALERT_MSG=" xtpsvr进程已停止运行\n> 服务器: $(hostname)\n> 时间: $(date "+%Y-%m-%d %H:%M:%S")"
# JSON消息体
JSON_MSG=$(cat <<EOF
{
"msgtype": "text",
"text": {
"content": "$ALERT_MSG",
"mentioned_mobile_list": ["@all"]
}
}
EOF
)
# 发送企业微信告警(后台执行避免阻塞)
nohup curl -s -X POST -H "Content-Type: application/json" -d "$JSON_MSG" "$WEBHOOK_URL" >/dev/null 2>&1 &
exit 1
fi