I want to collect statistics about who is using a computer and for how much time. I can use the users command to see who is logged in but I want to know who is on the currently active VT. I don't care about people who's logged in through SSH or who leaves a download running in a locked session. I only care about who actually sits in front of the machine.

I need information on X and console sessions.

Getting the time of the last activity (moving the mouse, etc) would be also useful but I can live without it.

How can I do this?

  • Can't you just get the output of w and then post process it a little? – Vitor Py Jul 24 '11 at 20:08
  • Well I can see which VT is active because that one has the smallest value in the IDLE column. But for X sessions it says ?xdm? instead of a time. – stribika Jul 24 '11 at 20:20

It looks like fgconsole (part of the kbd package on Fedora) does what you want.


That's what the wtmp file, and last command are for. Type last at a shell to see who has logged in, how long they were logged in, and from where. If they are currently logged on the command reports that.

The column showing where the user is/was logged in from will show a DISPLAY there, such as :0. Console users will have a tty matching tty[0-9]+.

To inspect this information from a program see man wtmp.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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