实时检查ssh端口转发服务是否在线并维持在线的监控脚本
This commit is contained in:
20
scripts/check_tunnel_v3.sh
Normal file
20
scripts/check_tunnel_v3.sh
Normal file
@@ -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 &
|
||||||
Reference in New Issue
Block a user