Execute Script on graphical logoff
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Execute Script on graphical logoff
Hello everyone
I wrote a scrpt that works perfectly when I execute it manual. Now I want to execute this everytime my graphical interface logs off.
I found the use of ~/bash_logout, but that is only executed when the shell is quited. i want to execute when ever i log out of cinemon
I wrote a scrpt that works perfectly when I execute it manual. Now I want to execute this everytime my graphical interface logs off.
I found the use of ~/bash_logout, but that is only executed when the shell is quited. i want to execute when ever i log out of cinemon
Last edited by donbolli on Sun Mar 17, 2024 6:01 am, edited 2 times in total.
Re: Execute Script on graphical logoff
I think you can put the script in
I never tried it though.
From /etc/X11/Xreset.d/README:
/etc/X11/Xreset.d/
I never tried it though.
From /etc/X11/Xreset.d/README:
# Scripts in this directory are executed as root when a user log out from
# a display manager using /etc/X11/Xreset.
# The username of the user logging out is provided in the $USER environment
# variable.
Re: Execute Script on graphical logoff
I tried it, it was not working. I assume I missed something, maybe rights or ownership?
It can be executed and it belongs to the default user
It can be executed and it belongs to the default user
Re: Execute Script on graphical logoff
Well, it was an estimated guess. I just tried it myself and indeed it didn't work.
Re: Execute Script on graphical logoff
Okay, any other ideas?
X11 is not Cinamon as far as I know
X11 is not Cinamon as far as I know
Re: Execute Script on graphical logoff
The only other idea I can think of is to broaden the question a bit.
What are you trying to fix?
What are you trying to fix?
Re: Execute Script on graphical logoff
I do have script checking for a process (bitcoin-core), shuts it down so nothing get lost
-
- Level 8
- Posts: 2240
- Joined: Wed Aug 14, 2019 1:02 am
Re: Execute Script on graphical logoff
Related old tutorial post that may serve your need: viewtopic.php?t=270140
Re: Execute Script on graphical logoff
This post worked, thank you.
Re: Execute Script on graphical logoff
the script is only excuted on logoff - not on restart or shutdown. how can i achive that?
-
- Level 8
- Posts: 2240
- Joined: Wed Aug 14, 2019 1:02 am
Re: Execute Script on graphical logoff
Restart/shutdown doesn't imply logoff? Or you mean you want to delay the execution until shutdown, not everytime you logoff?
Another old post suggested using systemd service viewtopic.php?t=278535
But...
If we stick with lightdm, there seems another hook for shutdown https://www.freedesktop.org/wiki/Softwa ... ystemhooks
Adding System Hooks
If you need some special behaviour when X servers and user sessions start/stop you can set commands to be run with the following configuration:
display-setup-script is run after the X server starts but before the user session / greeter is run. Set this if you need to configure anything special in the X server. It is run as root. If this command returns an error code the X server is stopped.Code: Select all
[SeatDefaults] display-setup-script=command display-stopped-script=command greeter-setup-script=command session-setup-script=command session-cleanup-script=command session-wrapper=command greeter-wrapper=command
display-stopped-script is run after an X server exits. It is run as root.
greeter-setup-script is run before a greeter starts. It is run as root. If this command returns an error code the greeter fails to start (which will cause LightDM to stop).
session-setup-script is run before a user session starts. If this command returns an error the session will not start (user is returned to a greeter).
session-cleanup-script is run after a greeter or user session stops. It is run as root.
session-wrapper is a the command to run for a session. This command is run as the user and needs to exec the command passed in the arguments to complete running the session. Use this if you need to do special setup for a user session. Note the default is 'lightdm-session' so you should chain to this if you need to override this setting.
greeter-wrapper is a the command to run a greeter. It is the equivalent of session-wrapper for greeters.
Re: Execute Script on graphical logoff
Thanks for that, I was aware of and use display-setup-script, I wasn't aware of the others.
If you want to know how to invoke those scripts from lightDM:
viewtopic.php?p=2209128#p2209128
If you want to know how to invoke those scripts from lightDM:
viewtopic.php?p=2209128#p2209128
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
- Qapla
- Level 2
- Posts: 73
- Joined: Tue Sep 14, 2021 5:35 pm
- Location: San Francisco, 6,437 meters SouthEast of the future home of Starfleet Academy
Re: Execute Script on graphical logoff
I am trying to do something similar, and can get the script to run at shutdown using either the session-cleanup-script or the systemd options, but they both run AFTER the GUI desktop is closed.
I want to run
How do I do that? Lightdm session-cleanup and systemd target multi-user are already too late.
I want to run
wmctrl -l -x > /home/$USER/Documents/wmctrl.txt
to list open windows BEFORE the windows close.How do I do that? Lightdm session-cleanup and systemd target multi-user are already too late.
Qapla' - Success! (Klingon salutation on departure to battle)
Re: Execute Script on graphical logoff
From my understanding "session-cleanup-script" should have worked. But somehow it did not trigger the script on reboot or shutdown. display-stopped-script seems to be working.
Re: Execute Script on graphical logoff
The script gets executed, but too late. The script needs to run on shutdown or logoff while the graphical interface is still active. Is it possible?
Re: Execute Script on graphical logoff
Track down the logoff and shutdown scripts, they are probably simple bash or python scripts which could be edited.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
-
- Level 8
- Posts: 2240
- Joined: Wed Aug 14, 2019 1:02 am
Re: Execute Script on graphical logoff
Some additional search lead me to an interesting example https://github.com/CGamesPlay/infra/blo ... ct.service
Unlike this example, we want the script to run as early as possible in the logoff/shutdown procedure. So I suggest we skip theCode: Select all
[Unit] Description=self destruct on poweroff # We want to stop this service pretty late in the shutdown process, but # before the network goes down. By setting Before=network.target, our self # destruct will only happen after everything which is After=network.target. Before=network.target user.slice machine.slice # But the self destruct requires the network to actually be active. After=systemd-networkd.service nss-lookup.target [Service] EnvironmentFile=-/etc/self-destruct.env ExecStop=/usr/local/sbin/hcloud-self-destruct --force Type=oneshot RemainAfterExit=yes [Install] WantedBy=multi-user.target
Before=
, and use After=graphical.target
instead.- Qapla
- Level 2
- Posts: 73
- Joined: Tue Sep 14, 2021 5:35 pm
- Location: San Francisco, 6,437 meters SouthEast of the future home of Starfleet Academy
Re: Execute Script on graphical logoff
No joy. I also tried adding an
ExexStart=/bin/true
since the suggested service includes RemainAfterExit.I know my script IS being executed at Restart and/or Shutdown because I also have a
touch /home/myid/kilroywashere.txt
in it - and kilroy shows up. But again the graphical interface is already closed.Journalctl shows the graphical interface closing almost immediately.
Code: Select all
Mar 18 11:34:34 P7Mint-VB systemd-logind[525]: System is rebooting.
Mar 18 11:34:34 P7Mint-VB systemd[1]: Stopping Session c2 of User linux...
Mar 18 11:34:35 P7Mint-VB systemd[1]: Removed slice Slice /system/modprobe.
Mar 18 11:34:35 P7Mint-VB systemd[1]: Stopped target Graphical Interface.
Mar 18 11:34:35 P7Mint-VB systemd[1]: Stopped target Multi-User System.
Mar 18 11:34:35 P7Mint-VB systemd[1]: Stopped target Login Prompts.
Mar 18 11:34:35 P7Mint-VB systemd[1]: Stopped target Sound Card.
Mar 18 11:34:35 P7Mint-VB systemd[1]: Stopped target Timer Units.
Code: Select all
Mar 18 11:34:35 P7Mint-VB systemd[1]: Stopping wmctrl.service...
Mar 18 11:34:35 P7Mint-VB systemd[1]: Stopping Web Services Dynamic Discovery host daemon...
Mar 18 11:34:35 P7Mint-VB listwindows[2718]: Cannot open display.
Mar 18 11:34:35 P7Mint-VB systemd[1]: wmctrl.service: Control process exited, code=exited, status=1/FAILURE
Mar 18 11:34:35 P7Mint-VB systemd[1]: wmctrl.service: Failed with result 'exit-code'.
Mar 18 11:34:35 P7Mint-VB systemd[1]: Stopped wmctrl.service.
WantedBy=multi-user.target
to WantedBy=graphical.target
but that generated an error.
Code: Select all
Mar 18 12:39:37 P7Mint-VB systemd[1]: /etc/systemd/system/wmctrl.service:1: Assignment outside of section. Ignoring.
Qapla' - Success! (Klingon salutation on departure to battle)
- Qapla
- Level 2
- Posts: 73
- Joined: Tue Sep 14, 2021 5:35 pm
- Location: San Francisco, 6,437 meters SouthEast of the future home of Starfleet Academy
Re: Execute Script on graphical logoff
Gaaaaah! Sometimes the solution is so simple it is almost too simple to be obvious.
I wondered ... gee, what actually happens when I click the menu button and choose Quit (the red power button) ?
It runs a simple one line script:
So, simply add your desired command(s) BEFORE the "exec" command. Mine is:
I'm satisfied. Thank you. Qapla' (Success!)
I wondered ... gee, what actually happens when I click the menu button and choose Quit (the red power button) ?
It runs a simple one line script:
/usr/bin/cinnamon-session-quit
So, simply add your desired command(s) BEFORE the "exec" command. Mine is:
Code: Select all
#!/bin/sh
wmctrl -l -x > /home/$USER/Documents/wmctrl.txt
exec "/usr/share/cinnamon-session"/cinnamon-session-quit.py $@
Qapla' - Success! (Klingon salutation on departure to battle)