Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'd like to make a command run every time I log out. Is there a way to do this?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

If you are speaking of logging out of a bash login shell, there's a solution with ~/.bash_logout — Run man bash in the terminal for more details.

If you are speaking of logging out of the X-window system, there are far too many ways to get yourself "logged out" for there to be any way to guarantee the command will run.

However, since you are the one doing the logging out, if you change your logout habit, this might work...

If you are running gnome, you might want to write a short script - maybe called "logo" - put it in ~/bin (and ensure ~/bin is in your PATH).

The "logo" script would do two things:

  1. Run whatever command you want to run when you logout.
  2. Run gnome-session-save with your choice of arguments.

Run man gnome-session-save in the terminal for more details on the arguments.

share|improve this answer
add comment

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.