Take the 2-minute tour ×
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.

Possible Duplicate:
Show a notification across all running X displays

As root, I am trying to execute a command on remote servers that pops-up a message window to users; the question is, without su - user (because it takes too much time for many users), how can the correct DISPLAY value for any user be obtained?

share|improve this question

marked as duplicate by Gilles, Michael Mrozek Jul 19 '12 at 22:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
have you tried using wall for the popup? –  lynxlynxlynx Jul 16 '12 at 21:48

1 Answer 1

Short: there is not the solution(TM) for what you want.

However, with sufficient knowledge about your setup it may be possible to develop a solution that works for you. I had the same problem once.

The reason why it's so difficult is that the Xserver is precicely not tied to a user. You can confirm that on any major Linux distribution by loging in to the desktop-environment of your choice, opening a terminal and typing in ps faux. It will show your display manager, with (at least) two child processes: a xserver and the parent process for all processes belonging to your user session. Note that the xserver is started as user root and NOT as the user your session belongs to.

What I did/do to match a certain xserver with a username I do a majority vote: I look at each user process and check to which xserver it is connected. From that knowledge I create a list which tells me for each user the ammount of processes that are connected to a specific xserver. An illustration of this table could look like this:

      |xserver :1| xserver :2 | xserver :3 | xserver :4
-------------------------------------------------------------
alice |    17    |      0     |      0     |       0
bob   |     0    |      0     |     14     |       0
eve   |     0    |     34     |      1     |       0
foo   |     1    |      1     |      1     |       8

With this table I perform a simple majority vote which yields the mapping:

  • User alice is using, i.e. sitting in front, of xserver :1
  • User bob is using xserver :3
  • User eve is using xserver :2
  • User foo is using xserver :4

This majority vote does not necessarily yield correct mappings however, for all my intents and purposes it's sufficient.

That's all you need. Now you can

DISPLAY=<ip.to.xserver>:1 xmessage -buttons yes,no,maybe -nearmouse "Do you want to go on a date with me?"

ask alice for a date.

The magic is the DISPLAY environmental variable which xapplications use to find out which xserver they should connect to. Most xapplications also accept the option -display. See the man page on xmessage and X.

Of course there are (so) many other ways to replace my majority vote with. Which is the best suited for you, you need to find out yourself ...

share|improve this answer

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