Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to write a startup script that would perform it's task if it was run on the local machine, but not if it was called from a remote xrdp session.

If Local
 do something
If remote
 do something else

How would I identify if the session is locally started or remotely started?

share|improve this question
make use of environment variables, such as $DISPLAY. – laebshade Oct 6 '12 at 2:02
it it safe to assume that the local $DISPLAY shall always be :0? the first PTY seems to be :10. Is there a way to be sure? – Lord Loh. Oct 6 '12 at 2:27
up vote 1 down vote accepted

This is unfortunately a very difficult problem. So in the general case, the answer is unfortunately no. Looking at $DISPLAY isn't sufficient as that just means that there is a local X server in some form (like xrdp), not that the user is physically at the machine.

The only option I'm aware of is ConsoleKit, which has a "is-local" attribute. Unfortunately I don't know any easy way to check it from a shell script. You might be able to do something using "ck-list-sessions".

Also note that it had a bug at one point where you could easily trick it to thinking a remote session was local.

If security isn't that important, then I suggest checking if xrdp sets some special environment variables that are only present for that kind of session. Just run "env" in a terminal and you'll see what's available.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.