Score:0

Execute script every time a user login/logout using a service (gdm)

kr flag

I'm a newbie in linux and I'll be glad for any help.
I'm using gdm and I want to execute a script **every time** a user login/logout .

To see that the mechanism works, I tried at first to execute the script for login only (and not logout).
I tried to run a service that does that by adding a service under /etc/systemd/user/serv.service.
Below is the Unit I wrote:

[Unit]
Description=service

[Service]
type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/user/Documents/scriptlogin
user=user

[install]
WantedBy=default.target

I enabled the service by systemctl --user start serv.service,
and I see that the script is executed only on reboot, but not on login/logout.
I'm not sure I understand the default.target line, but I'm guessing the runlevel is not changed when user logout or login, so that's why the script is not running again when logout and login again.

Does anyone know how should I fix it?

Thanks in advance!

Luuk avatar
cn flag
see: [How can I make a script run automatically after gdm login and logout?](https://askubuntu.com/questions/85985/how-can-i-make-a-script-run-automatically-after-gdm-login-and-logout)
user535733 avatar
cn flag
Logout scripts can be unreliable in some circumstances: Systems may crash or suffer power outages, or the user may hold down the power button. Then the script does not run.
Dvir Halutz avatar
kr flag
@Luuk Thanks. Actually that's the first thing I've tried, but we had issue with that too. Our script works when running it manually, but fail to when placed in those folders. We asked different question [here](https://askubuntu.com/questions/1379312/gdm-logout-script-doesnt-write-to-a-file)
Luuk avatar
cn flag
A, `those folders`, yep they seem to always cause a problem.... ?WTF?
karel avatar
sa flag
Does this answer your question? [How can I make a script run automatically after gdm login and logout?](https://askubuntu.com/questions/85985/how-can-i-make-a-script-run-automatically-after-gdm-login-and-logout)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.