Detect whether the current terminal is through mosh or not
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to figure out a way to detect whether the current terminal/connection (and under a tmux session as well) is through mosh or not.
From this thread, I found which pseudo-terminal session I am currently on:
$ tty
/dev/pts/69
So, I need to some information of the process that spawned this pseudo-terminal, or owns this tty as a children. With the information, perhaps I might be able to determine whether it is from sshd
or mosh
. But how can I do that?
Another challenge: If the current shell is under tmux, the retrieved tty might not match the sshd/mosh-server information since tmux also allocates another pseudo-terminal. Regardless of how the tmux session was created, I'll need to distinguish my current connection is from SSH or mosh. How will it be possible?
Some trials:
(1) For SSH, it was possible to find the sshd
process that matches the tty:
$ ps x | grep sshd | grep 'pts/27'
5270 ? S 0:00 sshd: wookayin@pts/27
So I can know the current connection is through SSH. However, through mosh, I could not find any relevant information.
(2) Using environment variables like SSH_CLIENT
or SSH_TTY
might not work because both ssh/mosh set these variables, and it is even wrong inside a tmux session.
ssh tty mosh
add a comment |Â
up vote
0
down vote
favorite
I am trying to figure out a way to detect whether the current terminal/connection (and under a tmux session as well) is through mosh or not.
From this thread, I found which pseudo-terminal session I am currently on:
$ tty
/dev/pts/69
So, I need to some information of the process that spawned this pseudo-terminal, or owns this tty as a children. With the information, perhaps I might be able to determine whether it is from sshd
or mosh
. But how can I do that?
Another challenge: If the current shell is under tmux, the retrieved tty might not match the sshd/mosh-server information since tmux also allocates another pseudo-terminal. Regardless of how the tmux session was created, I'll need to distinguish my current connection is from SSH or mosh. How will it be possible?
Some trials:
(1) For SSH, it was possible to find the sshd
process that matches the tty:
$ ps x | grep sshd | grep 'pts/27'
5270 ? S 0:00 sshd: wookayin@pts/27
So I can know the current connection is through SSH. However, through mosh, I could not find any relevant information.
(2) Using environment variables like SSH_CLIENT
or SSH_TTY
might not work because both ssh/mosh set these variables, and it is even wrong inside a tmux session.
ssh tty mosh
Usingps -p $PPID
, I could detect the parent ismosh-server
,tmux: server
orsshd
. However, tmux+mosh is still a complicated situation.
â Jongwook Choi
Oct 1 '17 at 23:26
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to figure out a way to detect whether the current terminal/connection (and under a tmux session as well) is through mosh or not.
From this thread, I found which pseudo-terminal session I am currently on:
$ tty
/dev/pts/69
So, I need to some information of the process that spawned this pseudo-terminal, or owns this tty as a children. With the information, perhaps I might be able to determine whether it is from sshd
or mosh
. But how can I do that?
Another challenge: If the current shell is under tmux, the retrieved tty might not match the sshd/mosh-server information since tmux also allocates another pseudo-terminal. Regardless of how the tmux session was created, I'll need to distinguish my current connection is from SSH or mosh. How will it be possible?
Some trials:
(1) For SSH, it was possible to find the sshd
process that matches the tty:
$ ps x | grep sshd | grep 'pts/27'
5270 ? S 0:00 sshd: wookayin@pts/27
So I can know the current connection is through SSH. However, through mosh, I could not find any relevant information.
(2) Using environment variables like SSH_CLIENT
or SSH_TTY
might not work because both ssh/mosh set these variables, and it is even wrong inside a tmux session.
ssh tty mosh
I am trying to figure out a way to detect whether the current terminal/connection (and under a tmux session as well) is through mosh or not.
From this thread, I found which pseudo-terminal session I am currently on:
$ tty
/dev/pts/69
So, I need to some information of the process that spawned this pseudo-terminal, or owns this tty as a children. With the information, perhaps I might be able to determine whether it is from sshd
or mosh
. But how can I do that?
Another challenge: If the current shell is under tmux, the retrieved tty might not match the sshd/mosh-server information since tmux also allocates another pseudo-terminal. Regardless of how the tmux session was created, I'll need to distinguish my current connection is from SSH or mosh. How will it be possible?
Some trials:
(1) For SSH, it was possible to find the sshd
process that matches the tty:
$ ps x | grep sshd | grep 'pts/27'
5270 ? S 0:00 sshd: wookayin@pts/27
So I can know the current connection is through SSH. However, through mosh, I could not find any relevant information.
(2) Using environment variables like SSH_CLIENT
or SSH_TTY
might not work because both ssh/mosh set these variables, and it is even wrong inside a tmux session.
ssh tty mosh
ssh tty mosh
asked Oct 1 '17 at 17:26
Jongwook Choi
50143
50143
Usingps -p $PPID
, I could detect the parent ismosh-server
,tmux: server
orsshd
. However, tmux+mosh is still a complicated situation.
â Jongwook Choi
Oct 1 '17 at 23:26
add a comment |Â
Usingps -p $PPID
, I could detect the parent ismosh-server
,tmux: server
orsshd
. However, tmux+mosh is still a complicated situation.
â Jongwook Choi
Oct 1 '17 at 23:26
Using
ps -p $PPID
, I could detect the parent is mosh-server
, tmux: server
or sshd
. However, tmux+mosh is still a complicated situation.â Jongwook Choi
Oct 1 '17 at 23:26
Using
ps -p $PPID
, I could detect the parent is mosh-server
, tmux: server
or sshd
. However, tmux+mosh is still a complicated situation.â Jongwook Choi
Oct 1 '17 at 23:26
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
I have come up with a decent solution to this, and wrapped it as a simple script: is_mosh.
The idea is quite simple: (i) to find the tmux client that is attached to the current tmux session, and then (ii) to search its ancestor processes to find if there is a mosh process.
It might not be complete, depending on environments, but I could succesfully detect and apply 24-bit color feature only if it's not running under mosh (as mosh doesn't support 24-bit colors). Here is a solution.
To avoid being flagged as a link-only answer, could you import the relevant bits of code into this Answer?
â Jeff Schaller
Oct 18 '17 at 11:09
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I have come up with a decent solution to this, and wrapped it as a simple script: is_mosh.
The idea is quite simple: (i) to find the tmux client that is attached to the current tmux session, and then (ii) to search its ancestor processes to find if there is a mosh process.
It might not be complete, depending on environments, but I could succesfully detect and apply 24-bit color feature only if it's not running under mosh (as mosh doesn't support 24-bit colors). Here is a solution.
To avoid being flagged as a link-only answer, could you import the relevant bits of code into this Answer?
â Jeff Schaller
Oct 18 '17 at 11:09
add a comment |Â
up vote
0
down vote
I have come up with a decent solution to this, and wrapped it as a simple script: is_mosh.
The idea is quite simple: (i) to find the tmux client that is attached to the current tmux session, and then (ii) to search its ancestor processes to find if there is a mosh process.
It might not be complete, depending on environments, but I could succesfully detect and apply 24-bit color feature only if it's not running under mosh (as mosh doesn't support 24-bit colors). Here is a solution.
To avoid being flagged as a link-only answer, could you import the relevant bits of code into this Answer?
â Jeff Schaller
Oct 18 '17 at 11:09
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I have come up with a decent solution to this, and wrapped it as a simple script: is_mosh.
The idea is quite simple: (i) to find the tmux client that is attached to the current tmux session, and then (ii) to search its ancestor processes to find if there is a mosh process.
It might not be complete, depending on environments, but I could succesfully detect and apply 24-bit color feature only if it's not running under mosh (as mosh doesn't support 24-bit colors). Here is a solution.
I have come up with a decent solution to this, and wrapped it as a simple script: is_mosh.
The idea is quite simple: (i) to find the tmux client that is attached to the current tmux session, and then (ii) to search its ancestor processes to find if there is a mosh process.
It might not be complete, depending on environments, but I could succesfully detect and apply 24-bit color feature only if it's not running under mosh (as mosh doesn't support 24-bit colors). Here is a solution.
answered Oct 8 '17 at 19:11
Jongwook Choi
50143
50143
To avoid being flagged as a link-only answer, could you import the relevant bits of code into this Answer?
â Jeff Schaller
Oct 18 '17 at 11:09
add a comment |Â
To avoid being flagged as a link-only answer, could you import the relevant bits of code into this Answer?
â Jeff Schaller
Oct 18 '17 at 11:09
To avoid being flagged as a link-only answer, could you import the relevant bits of code into this Answer?
â Jeff Schaller
Oct 18 '17 at 11:09
To avoid being flagged as a link-only answer, could you import the relevant bits of code into this Answer?
â Jeff Schaller
Oct 18 '17 at 11:09
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395491%2fdetect-whether-the-current-terminal-is-through-mosh-or-not%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Using
ps -p $PPID
, I could detect the parent ismosh-server
,tmux: server
orsshd
. However, tmux+mosh is still a complicated situation.â Jongwook Choi
Oct 1 '17 at 23:26