Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to run a script to rsync my home directory to another machine whenever I log out of Gnome. There is a way to hook into the Gnome logout process?

share|improve this question
up vote 5 down vote accepted

The script /etc/gdm/PostSession/Default is run by root whenever someone quits his X session. You might add there something like

if [ ${USERNAME} = "myuser" ];then
  su myuser -c /home/myuser/logout.sh

before the exit 0.

Then create a file /home/myuser/logout.sh, make it executable and add your rsync call to it.

share|improve this answer

You can add the script to the ~/.bash_logout script file (create it if it doesn't exist, but make sure to mark it as executable).

I'm actually searching for a way to do this only with the Gnome session, since using ~/.bash_logout will run for a Gnome session logout, but also any other (BASH) session logout as well (SSH console, etc.).

share|improve this answer

Your Answer


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.