From a1c33ca4688abf5199e25333edb549c69d3a13f6 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Fri, 27 Mar 2026 10:21:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E6=A3=80=E6=9F=A5ssh?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E8=BD=AC=E5=8F=91=E6=9C=8D=E5=8A=A1=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=9C=A8=E7=BA=BF=E5=B9=B6=E7=BB=B4=E6=8C=81=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=9A=84=E7=9B=91=E6=8E=A7=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/check_tunnel_v3.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 scripts/check_tunnel_v3.sh diff --git a/scripts/check_tunnel_v3.sh b/scripts/check_tunnel_v3.sh new file mode 100644 index 0000000..cf43536 --- /dev/null +++ b/scripts/check_tunnel_v3.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# 简单轮程宑控脚本 +# 每隔几秒检查一次轮程,轮程消失则执行命令 + +# ==================== 配置区域(只需改这里) ==================== +CHECK_INTERVAL=30 # 每隔多少秒检查一次 +CHECK_CMD="pgrep -f -c 'ssh -fCN tunnel-to-aliyun'" # 检查命令(轮程存在应返㮞0) +EXEC_CMD="ssh -fCN tunnel-to-aliyun" # 轮程消失后执行的命令 +# =============================================================== + +while true; do + if ! eval "$CHECK_CMD" >/dev/null 2>&1; then + echo "[$(date '+%H:%M:%S')] Process not found, executing: $EXEC_CMD" + eval "$EXEC_CMD" + sleep 60*5 + fi + sleep "$CHECK_INTERVAL" +done + +# nohup ./check_tunnel_v3.sh > check_tunnel_v3.log 2>&1 &