Is there something you want to do every time you log out: run a program that deletes temporary files, asks you a question, or prints a fortune to your screen? If you use the C shell, make a file named .logout (Section 3.3) in your home directory and put the commands there. Before a login C shell exits, it will read that file. A login bash reads .bash_logout, and zsh reads .zlogout. But not all shells are login shells; you might want these shells to read your logout-type file, too. Section 3.18 shows a fix for the Bourne and Korn shells; Section 3.8 and Section 3.4 have background information.
Some ideas for your logout file are:
A command like fortune to give you something fun to think about when you log out.
A command to list a "reminder" file -- for example, work to take home.
A script that prompts you for the hours you've worked on projects so you can make a timesheet later.
The command clear to erase your screen. This keeps the next user from reading what you did.[14] In the Mac OS X Terminal application, command-k will delete the scrollback buffer. It also helps to stop "burn-in" damage to old, monochrome monitors caused by characters left over from your login session (though this is hardly a concern nowadays; most of us have moved on to color screens that are not subject to burn-in). (Some Unixes clear the screen before printing the login: prompt. Of course, this won't help users who connect with a data switch or port manager because the connection will be broken before the next login prompt.)
[14]Some terminals and windows have "scroll back" memory of previous screens. clear usually doesn't erase all of that. To set scrollback in xterm, use the -sb and -sl options. Most other terminal emulators have similar mechanisms to set the number of lines to keep in the scrollback buffer.
If you connect to this host over a network, with a slow modem or on a data switch -- and you don't see all the logout commands run before your connection closes -- try putting the command sleep 2 (Section 25.9) at the end of the file. That makes the shell wait two seconds before it exits, which gives output more time to get to your screen.
--JP and SJC
Copyright © 2003 O'Reilly & Associates. All rights reserved.