I came up with this function to logout users (see at the bottom)
It assumes
- you have sudo permissions
- you have bash
- the users have 1 running X session (although you should be able to issue the same logout command multiple times to get rid of remaining sessions)
You can give it multiple usernames:
logout john jane mike elisa
And you can give it additional options:
logout john --force
So, I have the following helper function:
function forcelogout() {
logout "$@" --no-prompt --force
}
Notes:
- This is a blunt instruments and works by just copying the entire session environment. This could be more selective.
- Sometimes logout seems to take a while
- In rare occasions the session keeps being reported until someone visits the vt where the session ran, but nothing is there anymore)
CODE
function logout() {
local USERNAME
export USERNAMES=( )
while [ -n "$1" ]; do case "$1" in
-* ) break ;;
*) USERNAMES+=( "$1" ); shift ;;
esac; done
for USERNAME in "${USERNAMES[@]}"; do
local SESSION_PID=$(pgrep -fu "$USERNAME" gnome-session|head -1)
if [ -n "$SESSION_PID" ]; then
(
sudo -u "$USERNAME" cat "/proc/$SESSION_PID/environ" | xargs -0 -n 1 echo export
echo "gnome-session-quit --logout $@"
) | sudo -u "$USERNAME" sh -;
fi
done
}