Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In similar vein to my question for Windows and Mac OS X, how would one go about creating a logoff script for Linux?

Any distro is fine, as I'm sure it'd be extendable across others. I'm most familiar with RHEL/CentOS/Fedora and Ubuntu, though.

addition
If this exists for both a graphical login (ie at a lcoal workstation) and for a remote login (such as via ssh), that'd be ideal - but I'd settle for one or the other if both aren't possible.

share|improve this question

3 Answers 3

up vote 10 down vote accepted

For remote SSH sessions, it's the job of your shell to handle any on-logout scripting. The Bash shell typically runs ~/.bash_logout.

For X sessions, the login manager controls on-logout scripting. File locations depend on which login manager is in use. The Xserver is not running when the on-logout script is executed, so don't include any programs in the script that try to access the display.

  • For Gnome, use /etc/gdm/PostSession/Default for a system-wide default logout script (runs no matter who's logging out). Unlike Bash's logout script, I don't think there's a user-specific version of a GDM PostSession script.

  • XDM uses a Reset script is installed to /etc/X11/xdm/Xreset.

  • For KDE (using KDM), you want the Reset script. KDE3 uses /etc/kde3/kdm/Xreset. The location may be specified in KDM's configuration file, /etc/kde3/kdm/kdmrc, with the Reset key.

  • WDM apparently uses a pair of Reset scripts: a per-display script at /etc/X11/wdm/Xreset_0 (for display :0), and a global script at /etc/X11/wdm/Xreset. The WDM configuration file is in /etc/X11/wdm/wdm-config.

The file locations in this answer are from Debian packages. Ubuntu packages will generally use the same files, but other distributions may use alternate locations.

share|improve this answer
    
is there a similar feature for KDE or fluxbox or icewm? –  warren Nov 4 '09 at 17:27
1  
GDM is the Gnome-replacement for XDM, the X login manager. KDE's is KDM, i believe. there are others but those are the big three. i think WDM is often recommended for use with fluxbox? there's also SDM (SSH-based!) which probably provides scripting support. don't know more details; if i get a chance later i'll try to find out. –  quack quixote Nov 4 '09 at 17:45
    
awesome, thanks :) –  warren Nov 5 '09 at 13:13

The C-shell, a.k.a. csh, has the .logout functionality, and Bash (the more current default) has .bash_logout, but I don't remember any other shells (ksh, sh, etc) with a similar concept.

share|improve this answer

If the distro uses PAM to authentificate users, you can install pam_script to provide onsessionopen/onsessionclose funcionality.

I use it in Debian based distros to check files modified by users thru scp only and adjust the files' permissions.

You can download pam_script from freecode.

share|improve this answer

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.