How to get remote connection activity?

71 views
Skip to first unread message

katsusuke shimizu

unread,
Feb 4, 2020, 8:05:15 AM2/4/20
to tmate.io
How do I get remote connection activity?
 tmate is a really great tool for me. Thanks for the special tools.

I want to create a script to debug the CI server from outside.
My script starts a tmate session and listens for incoming connections.
The script stops running unit tests while the client is connected, but runs the unit test immediately if the client is never connected.
But I couldn't find a way to get remote connection activity.

  My script looks like this:


tmate -S /tmp/tmate.sock new-session -d
tmate -S /tmp/tmate.sock wait tmate-ready
tmate -S /tmp/tmate.sock display -p '#{tmate_web}'

./wait_connection

has_active_connection=$(HOW_TO_GET)

if [ -S /tmp/tmate.sock ] && [ $has_active_connection -eq 0 ]; then
tmate -S /tmp/tmate.sock display kill-server || echo "tmate server killed"
while [ -S /tmp/tmate.sock ]; do sleep 1; done
echo "tmate session closed"
fi
./run_test

Nicolas Viennot

unread,
Feb 17, 2020, 8:58:31 PM2/17/20
to katsusuke shimizu, tmate.io
Hello katsusuke,

It allows you to run tmate -S /tmp/tmate.sock display -p '#{tmate_num_clients}' to get the number of clients currently connected to the sesion.

However, for your use case, I would recommend using named session (see on https://tmate.io), and foreground mode.
Using the following:

$ echo set tmate-api-key tmk-XXXX > ~/.tmate.conf
$ echo set tmate-foreground-restart 0 >> ~/.tmate.conf
$ tmate -n ci -F

You can then connect to https://tmate.io/t/katsusuke/ci and access the terminal there. Once you close the shell, the tmate daemon would die, and your test would die too if nothing else is queued.

Let me know how it goes,
Nico 

--
You received this message because you are subscribed to the Google Groups "tmate.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmate-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tmate-io/7b648d08-77ba-4727-9510-896509e8c2f1%40googlegroups.com.

katsusuke shimizu

unread,
Feb 25, 2020, 3:10:44 AM2/25/20
to tmate.io
Thanks Nicolas.
I didn't expect you to add features so quickly.
I am very surprised and grateful.

$ tmate -S /tmp/tmate.sock display -p '# {tmate_num_clients}'

When I checked the above command, it worked perfectly as expected.


> I would recommend using named session (see on https://tmate.io), and foreground mode.

Should I understand that foreground mode and named session are needed for security?
(eg: A third party guesses the user of ssh and connects incorrectly.)



2020年2月18日火曜日 10時58分31秒 UTC+9 Nicolas Viennot:
To unsubscribe from this group and stop receiving emails from it, send an email to tmat...@googlegroups.com.

2020年2月18日火曜日 10時58分31秒 UTC+9 Nicolas Viennot:
To unsubscribe from this group and stop receiving emails from it, send an email to tmat...@googlegroups.com.

2020年2月18日火曜日 10時58分31秒 UTC+9 Nicolas Viennot:
To unsubscribe from this group and stop receiving emails from it, send an email to tmat...@googlegroups.com.

Nicolas Viennot

unread,
Feb 25, 2020, 10:56:25 AM2/25/20
to katsusuke shimizu, tmate.io
Not needed for security

To unsubscribe from this group and stop receiving emails from it, send an email to tmate-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tmate-io/194da4f1-5405-489d-bca7-23971653ffd1%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages