[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to determine from script if/where X is running



Hello Martin,

On 2008-03-26 16:25 +0100, Martin Kraus wrote:

> Hello,
>   is there a standard way in debian to determine on what VT and display is X
> running? Say I have a script that does something and I need to return output
> to the user, but the user can be in linux console or in X or X doesn't have to
> be running etc. So I need to determine if/where I should popup a window or
> if I just need to send text to the console.

Most programs simply check for the DISPLAY environment variable.  This
is not totally reliable as it can be changed at will, but if the user
messes around with that variable, it is considered his fault.  And
you're in good company.

> Thinking about it, is there any reliable way to find out how are different
> users logged into the box? ssh,console,running X.

The `who' command tells you on which terminal users are logged in.
Though in most cases it will simply report /dev/pts/<n> as the terminal,
and you cannot tell an xterm from an ssh login that way.  But you can
see who is logged in via a display manager and on the local consoles.

Sven


Reply to: