3

Running Ubuntu 12.04. I have many users logged in via SSH and opening an Openbox session. How do I loop through all the logged in users and their display number so that I can execute a command for specific users?

The command would be the extension of restarting a Java application that they have open.

I have tried who -a, but it doesn't seem to list any SSH users and their display number. I am able to get display numbers via cd /tmp/.X11-unix but not their corresponding user login.

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
john
  • 43
  • 5

1 Answers1

2

Try who or who -a. it displays the user name, TTY/PTS (with id), and the display number (if local) or remote location. See here for the manpages.

This is one local session and two SSH sessions:

:~$ who
myuser tty7         2015-09-10 00:44 (:0)
myuser pts/2        2015-09-13 19:32 (MyWorkstation.net)
myuser pts/4        2015-09-13 19:34 (MyWorkstation.net)
Frank Thomas
  • 35,097
  • 3
  • 77
  • 98
  • I have tried who -a, but it doesn't seem to list any SSH users and their display number. I am able to get display numbers via cd /tmp/.X11-unix but not their corresponding user login. – john Sep 13 '15 at 23:40
  • you should be able to determine the session by start time, as it will be the create date for the file in `/tmp/.X11-unix`. Also, if your connections are creating displays via X11, then you can find the display from `ps aux | grep X` and note the display number in the command, like `/usr/bin/Xorg :0` – Frank Thomas Sep 14 '15 at 00:02
  • `who` still provides display numbers on Xubuntu 19.10. – Stéphane Gourichon Feb 24 '20 at 18:04