Script to logoff KDE/Gnome desktop user session; you can use it from command line or from desktop via Lanucher

by on April 9, 2008 · 2 comments

  1. #!/bin/bash
  2. # Script to logoff KDE/Gnome user session.
  3. # With proper permission via sudo it is possible that rest of the users
  4. # can use the same script. You can create Launcher to use this script
  5. # from Linux desktop. Tested on Debian Linux 3.x, but it should work with
  6. # other Linux distros and FreeBSD
  7. # -----------------------------------------------
  8. # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
  9. # This script is licensed under GNU GPL version 2.0 or above
  10. # -------------------------------------------------------------------------
  11. # This script is part of nixCraft shell script collection (NSSC)
  12. # Visit http://bash.cyberciti.biz/ for more information.
  13. # -------------------------------------------------------------------------
  14.  
  15. # Bins, adjust them as per your UNIX/Linux/BSD system (default is Debian)
  16.  
  17. PS="/bin/ps"
  18. AWK="/usr/bin/awk"
  19. GREP="/bin/grep"
  20. XARGS="/usr/bin/xargs"
  21. KILL="/bin/kill"
  22.  
  23. # Send HUP signal to X server :)
  24. $PS aux | $GREP X | $GREP -v "grep" | $AWK '{ print $2}' | $XARGS $KILL -HUP $1


4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • al biheiri

    wow…um… grep for X and kill it? ..

  • Sameer

    Hope this helps somebody looking to find a command-line way to log out of a Gnome session:

    gnome-session-save –logout

    For more options, run:

    gnome-session-save –help

    I don’t use KDE, but came across this:

    dcop kdesktop default logout

    and

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

    (refs: forum.kde.org and kde.org)

Previous Script:

Next Script: