File size: 1,165 Bytes
9a46fa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

while true; do
    echo "[tmate-log] Launching new tmate session..." | tee /home/draco/tmate.txt

    # Start tmate session
    tmate -S /tmp/tmate.sock new-session -d
    tmate -S /tmp/tmate.sock wait tmate-ready

    echo "[tmate-log] SSH: $(tmate -S /tmp/tmate.sock display -p "#{tmate_ssh}")" | tee -a /home/draco/tmate.txt
    echo "[tmate-log] Web: $(tmate -S /tmp/tmate.sock display -p "#{tmate_web}")" | tee -a /home/draco/tmate.txt
    echo "[tmate-log] Monitoring connection (will restart in 3 hours)..." | tee -a /home/draco/tmate.txt

    # Monitor for 3 hours or until tmate process exits
    start_time=$(date +%s)
    while pgrep -f "tmate -S /tmp/tmate.sock" > /dev/null; do
        current_time=$(date +%s)
        elapsed=$((current_time - start_time))
        if [ $elapsed -ge 10800 ]; then
            echo "[tmate-log] ⏰ 3 hours passed. Restarting session..." | tee -a /home/draco/tmate.txt
            pkill -f "tmate -S /tmp/tmate.sock"
            break
        fi
        sleep 5
    done

    echo "[tmate-log] ⚠️ Connection lost or timeout. Reconnecting in 5 seconds..." | tee -a /home/draco/tmate.txt
    sleep 5
done