Remote logout from KDE 4.5

Hi,
I need to logout from a KDE 4.5 session remotely (via SSH) for a number of reasons. How can I do that from a bash shell?

Try this:

qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout 0 0 2

That is just for log out. You can play around with the settings and make it shutdown/reboot instead of log out. Here is a reference:
http://api.kde.org/4.x-api/kdebase-workspace-apidocs/libs/kworkspace/html/namespaceKWorkSpace.html#a9a0d278dba086dd42ae31fc483538b77a95eaf067045e95ee689a6772facfc812

One more thing. I would recommend putting this long line into a script with an easy to remember name. Do something like this on the remote machine:


echo "qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout 0 0 2" >> ~/bin/kderemotelogout.sh
chmod +x ~/bin/kderemotelogout.sh

Then you can easily log out remotely any time by just running


kderemotelogout.sh

Through ssh

Thank you for your answer.
Basically, I did just that, a script that logs out.

I receive the following error:
Couldn’t exec org.kde.ksmserver: No such file or directory
Then, I logged on with an ssh session and I run the qdbus whithout arguments:


qdbus
Could not connect to D-Bus server: org.freedesktop.DBus.Error.Spawn.ExecFailed: /bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.

The error was displayed when I was already logged on in X11 (and I had a hanged session!)
Now, that’s strange! Any ideas?

It looks like the API has changed since then; that command doesn’t work on KDE 4.11 or 4.12:

$ qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout 0 0 2
Cannot find 'org.kde.KSMServerInterface.logout' in object /KSMServer at org.kde.ksmserver

I couldn’t find any reference to “ksmserver” or “logout” in the KDE 4.12 API documentation which seemed relevant. Does anyone know what the new command to log out would be?