Created
November 3, 2011 11:44
-
-
Save tuxce/1336308 to your computer and use it in GitHub Desktop.
Get user's ck sessions and display their states
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ck_ds () { | |
local object=$1 interface=$2 method=$3; shift 3 | |
dbus-send --system --type=method_call --print-reply \ | |
--reply-timeout=2000 \ | |
--dest=org.freedesktop.ConsoleKit \ | |
"/org/freedesktop/ConsoleKit/$object" \ | |
"org.freedesktop.ConsoleKit.$interface.$method" "$@" | |
} | |
ck_ds_get_res () { | |
local res_type=$1; shift | |
ck_ds "$@" | sed -n -e "s/.* $res_type \(.*\)/\1/p" | |
} | |
cur_session=$(ck_ds_get_res "object path" Manager Manager GetCurrentSession) | |
[[ ! $cur_session ]] && echo "Pas de session CK" && exit 1 | |
cur_session=${cur_session%\"} | |
cur_session=${cur_session##*/} | |
for _sess in $(ck_ds_get_res "object path" Manager Manager GetSessionsForUnixUser uint32:$UID); do | |
sess=${_sess%\"} | |
sess=${sess##*/} | |
is_active=$(ck_ds_get_res boolean $sess Session IsActive) | |
is_local=$(ck_ds_get_res boolean $sess Session IsLocal) | |
[[ $sess == $cur_session ]] && echo -n "*" || echo -n " " | |
echo -e "Session: $sess\tActive: $is_active\tLocal: $is_local" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment