How to find out the currently active linux virtual terminal while connected via ssh?
Solution 1
fgconsole is what you are looking for
http://linux.die.net/man/1/fgconsole
Solution 2
Alternatively, if you do not want to use sudo
to figure out what the current tty
is, you can use Linux-specific sysfs
entry:
$ cat /sys/class/tty/tty0/active
tty8
Related videos on Youtube
vadipp
Open-minded IT-specialist. My favourites are Scala, Perl and Linux.
Updated on September 18, 2022Comments
-
vadipp over 1 year
The situation is as follows.
I have a multiuser desktop machine with Debian Linux 6.0 and an ATI videocard with one monitor connected. I have root access to it. There can be several KDE sessions started, like this:
$ w 21:51:30 up ? days, 4:22, ? users, load average: 1.72, 1.68, 1.67 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT u1 pts/0 :0 Sat18 4days 0.00s 11.68s kdeinit4: kded4 [kdeinit] u2 pts/5 :1 Mon17 2days 0.00s 6.65s kdeinit4: kded4 [kdeinit]
So, two virtual terminals are in use, tty7 and tty8:
$ ps aux|grep /usr/bin/[X] root 2944 3.1 12.4 670040 1019904 tty7 Ss+ Aug27 187:52 /usr/bin/X :0 vt7 -br -nolisten tcp -auth /var/run/xauth/A:0-?????? root 5507 0.9 3.7 425136 309676 tty8 Ss+ Aug29 29:38 /usr/bin/X :1 vt8 -br -nolisten tcp -auth /var/run/xauth/A:1-??????
But of course only one of them is active at any given moment, i.e. displayed on the monitor. Someone sitting at the keyboard can switch between them using Ctrl+Alt+F[78]
So, I connect via ssh from a remote host. I need to know which X DISPLAY is active now. Is it possible? I have googled all over the place and can't find the answer.
-
vadipp over 12 yearsSorry, but it does not do what I want. It just prints
Couldnt get a file descriptor referring to the console
. Any ideas of what might be the reason? -
vadipp over 12 yearsI was stupid enough to not use sudo :) With sudo, it works like a charm. Thanks a lot, problem solved!