Spaces:
Paused
Paused
ayoub ayoub
commited on
Create run_tmate.sh
Browse files- run_tmate.sh +36 -0
run_tmate.sh
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
LOG_FILE="/home/draco/.tmate_hidden.txt"
|
| 4 |
+
|
| 5 |
+
while true; do
|
| 6 |
+
{
|
| 7 |
+
echo "[tmate-log] Launching new tmate session..."
|
| 8 |
+
|
| 9 |
+
# Start tmate in daemon mode with a socket
|
| 10 |
+
tmate -S /tmp/tmate.sock new-session -d
|
| 11 |
+
tmate -S /tmp/tmate.sock wait tmate-ready
|
| 12 |
+
|
| 13 |
+
SSH_URL=$(tmate -S /tmp/tmate.sock display -p "#{tmate_ssh}")
|
| 14 |
+
WEB_URL=$(tmate -S /tmp/tmate.sock display -p "#{tmate_web}")
|
| 15 |
+
|
| 16 |
+
echo "[tmate-log] SSH: $SSH_URL"
|
| 17 |
+
echo "[tmate-log] Web: $WEB_URL"
|
| 18 |
+
echo "[tmate-log] Monitoring connection (will restart in 3 hours)..."
|
| 19 |
+
|
| 20 |
+
start_time=$(date +%s)
|
| 21 |
+
while pgrep -f "tmate -S /tmp/tmate.sock" > /dev/null; do
|
| 22 |
+
current_time=$(date +%s)
|
| 23 |
+
elapsed=$((current_time - start_time))
|
| 24 |
+
if [ $elapsed -ge 10800 ]; then
|
| 25 |
+
echo "[tmate-log] ⏰ 3 hours passed. Restarting session..."
|
| 26 |
+
pkill -f "tmate -S /tmp/tmate.sock"
|
| 27 |
+
break
|
| 28 |
+
fi
|
| 29 |
+
sleep 5
|
| 30 |
+
done
|
| 31 |
+
|
| 32 |
+
echo "[tmate-log] ⚠️ Connection lost or timeout. Reconnecting in 5 seconds..."
|
| 33 |
+
sleep 5
|
| 34 |
+
|
| 35 |
+
} >> "$LOG_FILE" 2>&1
|
| 36 |
+
done
|