Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to know if someone is logged into a local X-session. In the past I looked at the output of ck-list-sessions. The output looked something like this:

Session12:
    unix-user = '[redacted]'
    realname = '[redacted]'
    seat = 'Seat1'
    session-type = ''
    active = TRUE
    x11-display = ':0'
    x11-display-device = '/dev/tty8'
    display-device = ''
    remote-host-name = ''
    is-local = TRUE
    on-since = '2012-10-22T18:17:55.553236Z'
    login-session-id = '4294967295'

If no one was logged in, there was no output. I checked if someone was logged in with

ck_result" string => execresult("/usr/bin/ck-list-sessions | /bin/grep x11 | /usr/bin/cut --delimiter=\\' -f 2 | /usr/bin/wc -w

This no longer works, because lightdm greeter looks like a logged in user

Session12:
    unix-user = '[redacted]'
    realname = 'Light Display Manager'
    seat = 'Seat1'
    session-type = 'LoginWindow'
    active = TRUE
    x11-display = ':0'
    x11-display-device = '/dev/tty8'
    display-device = ''
    remote-host-name = ''
    is-local = TRUE
    on-since = '2012-10-22T22:17:55.553236Z'
    login-session-id = '4294967295'

I guess I could check session-type, but I don't know how to do that and check x11-display in one-liner. I then need to write my own script, but at that point I thought I would check if anyone else has already done the work or if there is a way to get ConsoleKit to tell me what I want (or if I should be using a different tool)?

share|improve this question
add comment

1 Answer

See the answer to this question. You will probably end up using D-Bus and ConsoleKit.

share|improve this answer
    
I may go with parsing the output of ck-list-sessions. That seems simpler that going through dbus, which isn't really designed for human interaction. –  Jack Oct 23 '12 at 15:01
    
I figured out how to use the dbus interface, but it doesn't appear to provide different information than is available with ck-list-sessions (which is probably using dbus under the hood). –  Jack Oct 23 '12 at 15:08
    
Now that I looked up ck-list-sessions I feel dumb; this is ConsoleKit, so the answers are essentially equivalent! –  January Oct 23 '12 at 16:55
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.