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.

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?

share|improve this question
    
Can't you just get the output of w and then post process it a little? –  Vitor 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
add comment

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.