Indiana University

IU Webmaster

Creating .logout script

  • A logout script is a short list of commands that are typically executed when you log out.
  • With a logout script, you can double check for any background jobs when logging out.
  • To create a logout script, create a file called .logout in your account's login directory, and enter the content below.
  • Please note that the .logout file needs to have the file permission set to 700.

ps -u `whoami` | grep -v $$ | grep -v 'PID TTY'

if ( $? == 0 ) then
echo ""
echo "WARNING - YOU HAVE RUNNING JOBS!"
echo ""
echo "press return to log out"
read answer

endif


When you logout, the .logout file will get executed. The script looks for any processes running under your username other than the shell which you are about to exit. If it finds a process, it will display it as well as the warning message, and require you to press return to continue your logout.

This script does not “auto-kill” a background job. It basically acts as a warning as you log out. If you did get a warning as you logged out, you would have to log back on and issue a kill command to terminate the process.