near / run_tmate.sh
ayoub ayoub
Create run_tmate.sh
4938a3d verified
#!/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