16

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.

3 Answers 3

14

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.

2
  • is there a similar feature for KDE or fluxbox or icewm?
    – warren
    Nov 4, 2009 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. Nov 4, 2009 at 17:45
6

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.

5

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .