UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 3.1 Running Commands When You Log Out Chapter 3
Logging Out
Next: 3.3 Electronic Fortune Cookies
 

3.2 Running Commands at Bourne/Korn Shell Logout

The C shell has a setup file named .logout (2.2). Commands in .logout are run when you log out. The Bourne and Korn shells don't have a logout file, though. Here's how to make one:

  1. In your .profile file, add the line:

    trap . 
    trap '. $HOME/.sh_logout; exit' 0

    (Some systems may need $LOGDIR instead of $HOME.)

  2. Make a file in your home directory named .sh_logout. Put in the commands you want to be run when you log out. For example:

    if [ -f 
    
    
    
    
    clear
    if [ -f $HOME/todo.tomorrow ]
    then
        echo "=========== STUFF TO DO TOMORROW: ============"
        cat $HOME/todo.tomorrow
    fi

The trap will read the .sh_logout file when the shell exits.

- JP


Previous: 3.1 Running Commands When You Log Out UNIX Power ToolsNext: 3.3 Electronic Fortune Cookies
3.1 Running Commands When You Log Out Book Index3.3 Electronic Fortune Cookies

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System