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