Files
liteadmin/tunnel.sh
T

20 lines
555 B
Bash
Raw 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
# 公网隧道自动重连脚本
# 使用 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