Pre-Logout Script

Erik Habicht erik.habicht at gmail.com
Sun Nov 18 18:57:18 CET 2012


On 18.11.2012 14:20, houghi wrote:
> On Sun, Nov 18, 2012 at 12:55:07PM +0100, Erik Habicht wrote:
>> Hi Hartmut,
>>
>> thank you for your hint. But it doesn't work since .bash_logout only work with
>> a login shell. Never the less i add "logger test" to .bash_logout. But when i
>> logout from my xfce session i can't see a log message in /var/log/syslog.
>>
>> The search continues.
> http://stackoverflow.com/questions/7579438/how-to-execute-a-script-when-xfce-session-ends
> That is what I found using google.
>
>
> What it is is moving /usr/bin/xfce4-session to /usr/bin/xfce4-session.orig
> Next make a new bash script /usr/bin/xfce4-session with e.g.:
>
> #!/bin/bash
> echo "Login  : `date`" >> /tmp/testfile # Here whatever you want
> /usr/bin/xfce4-session.orig
> echo "Logout : `date`" >> /tmp/testfile # Here whatever you want
>
> It would be nice to have the ability to do this nativaly in XFCE like you
> can start programs when XFCE launches.
>
> Even pointing just one program to see if it is there and if it is, run it,
> would be great.
> e.g. it could look at /usr/local/bin/xfce4-shutdown.sh and if it is
> available, run it.
> Or on any other place that won't overwrite the script.
>
> That would be a fast way of doing this. Doing it so that you can select
> programs like with an update would be more consitant, but harder to
> implement, I would think.
>
> Unless there already is a way to do all this, that is.
>
> houghi

Hi Houghi,

thank you for your research and the simple working solution. I tried it
out and it works as expected. But i implement it a little bit different.
Instead of moving the /usr/bin/xfce4-session to
/usr/bin/xfce4-session.orig i add a /usr/local/bin/xfce4-session that
invoke /usr/bin/xfce4-session.

In the meantime i worked out another solution. It's the more native way,
but not so simple. I add a system call to xfce4-session/xfsm-manager.c
that runs 'run-parts /etc/xfce/pre-logout.d'. The patch is not ready for
production but it works.
I think running a shell script as you said instead of use run-parts
could be the better solution since run-parts is not part of all
distribution.

This is the code that runs pre logout:

killall -TERM vmplayer

VM=`ps ax | grep vmplayer | grep -v grep`
while [ -n "$VM" ]
do
   VM=`ps ax | grep vmplayer | grep -v grep`
   sleep 1
done

Now my vm get proper suspended.


More information about the Xfce mailing list