Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to do some stuff at logout, and the task can take up to 5 minutes to complete.

If the user chooses Power off or Reboot directly, the script is killed before completion. If the user just chooses Log out, the script is executed with no problems.

I've tried using pam_exec and lightdm property session-cleanup-script to point to my script, but it's the same in both cases.

The script used to do the testing is this one:

#!/bin/bash
touch /tmpfile
for p in $(seq 0 300) ; do
    sleep 1
    echo $p >> /tmpfile
done

When logging out, all the 300 numbers are written to the file. When shutting down or rebooting directly from within the user session, only 2 or 3 numbers are written, so the script is being killed.

How is handled the shutdown by lightdm? How can I ensure my script is not being killed?

If you propose an alternative approach, please take care that I need to know what user is being logged out and be able to run a script as that user. I also need to notify the user about what's happening, so better stay on X if possible.

share|improve this question

1 Answer

LightDM

Create a script in /etc/rc0.d.

sudo vim /etc/rc0.d/myScript
sudo chmod +x /etc/rc0.d/myScript

GDM

Add your command to the file /etc/gdm/PostSession/Default before the exit 0 line.

As before shutdown the user is logged off anyway, this should cover both bases.

share|improve this answer
There is no /etc/gdm/PostSession/Default file. I'm using lightdm for instance. I've created it anyways, but that didn't help. That script is never run. – Jorge Suárez de Lis Feb 1 at 10:53
See the edit. Should work now.. – abhshkdz Feb 1 at 11:27
I need to know if a user is logging out, and what user, so that won't help. – Jorge Suárez de Lis Feb 1 at 11:43
Also, it would be better to stay on the an X session, because I need to show some output to the user. I'm adding this information to the main post. – Jorge Suárez de Lis Feb 1 at 11:53

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.