File size: 1,154 Bytes
4938a3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
#!/bin/bash

LOG_FILE="/home/draco/.tmate_hidden.txt"

while true; do
    {
        echo "[tmate-log] Launching new tmate session..."

        # Start tmate in daemon mode with a socket
        tmate -S /tmp/tmate.sock new-session -d
        tmate -S /tmp/tmate.sock wait tmate-ready

        SSH_URL=$(tmate -S /tmp/tmate.sock display -p "#{tmate_ssh}")
        WEB_URL=$(tmate -S /tmp/tmate.sock display -p "#{tmate_web}")

        echo "[tmate-log] SSH: $SSH_URL"
        echo "[tmate-log] Web: $WEB_URL"
        echo "[tmate-log] Monitoring connection (will restart in 3 hours)..."

        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..."
                pkill -f "tmate -S /tmp/tmate.sock"
                break
            fi
            sleep 5
        done

        echo "[tmate-log] ⚠️ Connection lost or timeout. Reconnecting in 5 seconds..."
        sleep 5

    } >> "$LOG_FILE" 2>&1
done