20 lines
555 B
Bash
20 lines
555 B
Bash
#!/bin/bash
|
||
# 公网隧道自动重连脚本
|
||
# 使用 localhost.run 将本地端口暴露到公网
|
||
|
||
LOCAL_PORT=${1:-8080}
|
||
|
||
while true; do
|
||
echo "[$(date '+%H:%M:%S')] 正在连接隧道..."
|
||
ssh -o StrictHostKeyChecking=no \
|
||
-o ServerAliveInterval=15 \
|
||
-o ServerAliveCountMax=3 \
|
||
-o ExitOnForwardFailure=yes \
|
||
-R 80:localhost:$LOCAL_PORT \
|
||
nokey@localhost.run 2>&1 | tee /tmp/tunnel.log
|
||
|
||
EXIT_CODE=$?
|
||
echo "[$(date '+%H:%M:%S')] 隧道断开 (exit=$EXIT_CODE),5秒后重连..."
|
||
sleep 5
|
||
done
|