B
B
bigov2018-02-25 04:24:02
linux
bigov, 2018-02-25 04:24:02

Does Linux/*BSD have a generic command to determine the console?

Hello. How can I automatically determine in which environment the command is run - in a console with the ability to access the X display and run GUI applications, or remotely? For example:

$ who
bob       tty7         2018-02-20 19:32 (:0)
bob       pts/0        2018-02-25 09:48 (126.126.68.117)

Bob has two sessions - local and remote. How to determine in which session the typed command is executed? For example, to automatically start a GUI application or display only the result in the console.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bigov, 2018-02-26
@bigov

Checking showed that tty gives /dev/pts/N both remotely and locally.
You can check for a remote SSH session by setting the $SSH_CLIENT environment variable. And since almost no one works using the telnet protocol (I don’t know any other connection options), you can use this as a solution to the issue.

S
Saboteur, 2018-02-25
@saboteur_kiev

$tty
/dev/pts/0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question