Score:1

Is there a default way to run commands on user's logout?

gf flag

I want to log the logins/logouts of my users.

For the logins I only need to modify /etc/profile and add my command or edit any .profile for an specific user.

But for the logouts I don't know if there is a default/centralized way to do it like /etc/profile for logins.

I see some example for CLI sessions, but I want to register GUI/CLI sessions.

Thanks

hr flag
I'm not sure you can rely on /etc/profile for non-shell sessions in general - even for logins. To do this properly, you'll probably need to use PAM. See for example [Hook into linux authentication to run script or program when certain conditions are met](https://stackoverflow.com/questions/5284624/hook-into-linux-authentication-to-run-script-or-program-when-certain-conditions) or another project that appears to be more active [pam-hooks](https://upsilon.cc/~zack/hacking/software/pam-hooks/)
gf flag
thanks for the comment, i've been using /etc/profile without problems and works smoothly. Nevertheless i'll check it out your recommendation
hr flag
I'm not saying `/etc/profile` can't work - it's just that it relies on the user's X (or Wayland etc.) session being started as a child of a Bourne-type login shell - which is not a given. See for example [X session wrapper](https://wiki.archlinux.org/title/LightDM#X_session_wrapper).
user535733 avatar
cn flag
Actions upon logout won't run in the event of a crash or system reset or power loss. So you must also create a check at login to discover whether the logout job ran.
Artur Meinild avatar
vn flag
Does this answer your question? [execute script when closing terminal](https://askubuntu.com/questions/1021971/execute-script-when-closing-terminal)
Score:1
in flag
CPH

Found this thread: https://unix.stackexchange.com/questions/208277/how-can-i-set-a-bash-logout-for-all-users

From the manual (man bash):

When a login shell exits, bash reads and executes commands from the files ~/.bash_logout and /etc/bash.bash_logout, if the files exists.
gf flag
that is for CLI not for GUI, isn't it?
CPH avatar
in flag
CPH
I know it works for CLI. Not sure about GUI however. If you are wanting specifically for GUI I must have misunderstood the question. I'm not sure of in that case
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.