12

Previously in Karmic, we created a logout script that does some work in the background on backing up a users home directory, this script was put in the /etc/GDM/PostSession directory.

I can't figure out where to put a script that I want to run during a logout in LightDM.

I've searched and have found many people who are looking for this answer, so any help would be greatly appreciated.

kiri
  • 28,246
  • 16
  • 81
  • 118

3 Answers3

10

At least since Ubuntu 12.04 there is now an option session-cleanup-script which can be added to the [SeatDefaults] section of /etc/lightdm/lightdm.conf. /usr/share/doc/lightdm/lightdm.conf.gz is the documentation:

# session-cleanup-script = Script to run when quitting a user session (runs as root)

Do not forget chmod +x yourscript to give your script executing permission.

After changing a value in lightdm.conf it takes only effect after lightdm is restarted. You can either reboot or login to a console (Ctrl+Alt+F1) and run sudo restart lightdm.

(Thanks to Krytarik who posted this answer in http://ubuntuforums.org/showthread.php?t=1918649)

elmicha
  • 9,728
  • 1
    If you add a cleanup script and log out, it won't work immediately. It seems as if you have to reboot first. – lumbric May 27 '12 at 19:26
  • 1
    You only have to restart lightdm. I'll edit my answer. – elmicha May 28 '12 at 08:26
  • Yeah I thought so, but I didn't think of that and tried 15 times to log out and in again. Fortunately I didn't delete my test script and after reboot (I had given up already) it worked... :) – lumbric May 28 '12 at 09:08
  • In Ubuntu 16.04 this can cause side effects. session-cleanup-script is also called if the user has typed wrong username or password. I'm currently searching for another way to setup a logout script which is really called only if the user logs out. – Michael Nov 16 '16 at 09:15
3

Add

session-setup-script = Script to run when starting a user session (runs as root)

session-cleanup-script = Script to run when quitting a user session (runs as root)

in /etc/lightdm/lightdm.conf file.

Sources:

Radu Rădeanu
  • 169,590
user55822
  • 3,125
  • 1
  • 17
  • 13
2

This is not possible. I think you need to follow bug in launcpad

Guria
  • 105